The MD5 algorithm, in different programming languages
The purpose of this page is to present timing results which can be more or
less compared. The MD5 algorithm does quite a bit of integer math and is
sufficiently complex to consume measurable amounts of time (some timings
were clocked with a loop and a watch - all have 2-digit precision).
June 2001 - New optimized entries (all are based on inlining):
- 31 ms in Perl 5.6.0, submitted by Doug Bagley, see
doug2md5.pl
(replacing his previous 74 ms version,
dougmd5.pl)
- 48 ms in Tcl, submitted by Miguel Sofer, see
migmd5.tcl
- 270 ms in Python, submitted by Christian Tismer, see
md5py.py
Note: Python's timings are due to unlimited-precision arithmetic, for a
hint that it could be in the 40..50 ms range, see
md5/ctmsg.txt and
ctmd5.intpy.
(Latest Forth results as of Dec 18, 2000 are
here)
Language Version Time (ms) Implementation
Linux SuSE 6.4 PIII/650:
C gcc 2.95.2 0.24 Portable compiled C
iForth 1.11d 0.35 Native-code Forth [*]
BigForth 1.22 1.5 Native-code Forth
GForth 0.5.0 15 GCC-specific optimized C
pForth v21 59 Threaded VM in standard C
Ficl 2.04 84 Threaded VM with C subr's
Lua 4.0 150 Lua bytecode VM in C
Tcl 8.4a2 180 Tcl bytecode VM in C
Perl 5.005 230 Perl bytecode VM in C
Python 2.0 460 Python bytecode VM in C
[*] reported by Marcel Hendrix (modified, but still pure Forth)
MacOS 9.0.4 G3/300:
Mops 4.01 2.9 Native-code Forth
Tcl 8.4a2 380 Tcl bytecode VM in C
Notes
- Timings are based on computing the MD5 hash of a string of 10,000 spaces
- The C timings were done in Python 2.0, using the built-in module
- The Forth and Python source code do not appear to be highly optimized
- If you send me code and if I can run it, I will add the results to the list
- Improvements to the code will be most gratefully acknowledged
- This is not an attempt to "win" or "prove", but to explore and learn
References
- Unofficial MD5 homepage - by Mordechai T. Abzug
-
http://userpages.umbc.edu/~mabzug1/cs/md5/md5.html
- Language implementations - various authors
-
BigForth -
GForth -
iForth -
Mops -
pForth -
and -
Lua -
Perl -
Python -
Tcl
- Forth - by Fredrick W. Warren
-
md5.fth (from comp.lang.forth)
- Lua - by Coen Siegerink
-
md5calc.lua
- Perl - by Alex Rousskov
-
http://www.cs.ndsu.nodak.edu/~rousskov/research/cache/sanitar/
- Python - by Christian Tismer
-
pymd5.py (on this site, not elsewhere AFAIK)
- Tcl - by Don Libes
-
http://expect.nist.gov/md5pure/
-- Coen Siegerink <jcw at equi4.com>