# [erlang-questions] Pointless md5 Problem

Matthias Lang <>
Thu May 7 09:55:01 CEST 2009

```On Wednesday, May 06, Matt Stancliff wrote:

> Anyway, my point was the crypto version is faster.

That depends.

The original poster was doing something special: generating MD5 hashes
of very short data---list representations of (possible) MD5 hashes, i.e.
32-character lists.

Trying that on my machine using your code:

1> Data = "5dde0325f904678067382b3297ae948f".
"5dde0325f904678067382b3297ae948f"
2> C = fun(Module, Data) -> {Time, _} =timer:tc(Module, md5, [Data]), Time end.
#Fun<erl_eval.12.102015280>
3>  N = 4000.
4000
4> lists:sum([C(crypto, Data) || _ <- lists:seq(1,N)])/N.
5.21000
5> lists:sum([C(erlang, Data) || _ <- lists:seq(1,N)])/N.
1.22300

i.e. for that data, on Erlang R11B on a 32-bit linux machine, the
crypto driver is _slower_. I get closer results on R13B on a 64-bit
machine, but still slower.

Matt

Looks to be over
> five times faster:
> ()190> C = fun(Module, Data) -> {Time, _} =
> timer:tc(Module, md5, [Data]), Time end.
> #Fun<erl_eval.12.113037538>
> ()192> N = 4000.
> 4000
> ()193> lists:sum([C(crypto, Data) || _ <- lists:seq(1,
> N)])/N.
> 12041.3115
> ()194> lists:sum([C(erlang, Data) || _ <- lists:seq(1,
> N)])/N.
> 63903.586
> ()195> 63903.586/12041.3115.
> 5.307028723573841
>
>
> Sorry for the confusion,
>
> -Matt

```