[erlang-questions] erlang:md5/1 vs crypto:md5/1 difference: speed

Bjorn Gustavsson <>
Sun Feb 1 09:49:11 CET 2009


On Sat, Jan 31, 2009 at 5:43 AM, Scott Lystig Fritchie
<> wrote:
> Hi, all.  Two years ago, Roberta Saccon asked a question of the
> difference between erlang:md5/1 vs crypto:md5/1.
>
> One answer was, "none."  Another answer was, "You need to start the
> crypto application before calling crypto:md5/1."
>
> I've discovered a third answer: speed.  On a newer Intel Xeon single
> CPU, dual-core box @ 2.33GHz, and on an AMD X2 single CPU, dual-core
> box, crypto:md5/1 is 3.0-3.5 times faster on a 64KByte blob than
> erlang:md5.  On an older 3.4GHz single core Xeon, the difference is over
> almost 7x, and on a several-year-old Pentium M laptop @ 1.33GHz, the
> difference is 8x.(*)
>

The MD5 BIFs are specially written not to block the virtual
machine/the scheduler
it is running in. It will process data up to a certain limit, and then
do what we
call a trap. It basically means that the Erlang process executing the BIF will
be scheduled out allowing other processes to run and then scheduled in
to continue
working with the BIF.

Another reason the BIFs are slower is that the OpenSSL version of the MD5
calculation is probably a lot more optimized (it might even be in assembly
language) than the BIF version.

/Bjorn

-- 
Björn Gustavsson, Erlang/OTP, Ericsson AB



More information about the erlang-questions mailing list