performance note sha1 vs md5 in python
Robert Collins
robertc at robertcollins.net
Mon Aug 6 04:30:40 BST 2007
I just ran the following test code:
contentlength=1024*1024
content="a"*contentlength
from sha import new
s = new()
for x in xrange(64):
s.update(content)
Using timeit, on python 2.4 and 2.5, and replacing the sha with md5 for
two runs.
The timeit command line is less legible :):
$ python -m timeit -s 'contentlength=1024*1024' -s
'content="a"*contentlength' -s 'from sha import new' 's = new()' 'for x
in xrange(64):' ' s.update(content)'
python 2.5 sha
10 loops, best of 3: 637 msec per loop
python 2.5 md5
10 loops, best of 3: 375 msec per loop
python 2.4 sha
10 loops, best of 3: 1.11 sec per loop
python 2.4 md5
10 loops, best of 3: 537 msec per loop
Within python 2.4, md5 is 2.06 times faster than sha
Within python 2.5, md5 is 1.69 times faster than sha
(at encoding 64MB in 1MB chunks)
So this note is to suggest that where we need a broadly spread hash
function where the vulnerability of the hash to attacks doesn't diminish
its usefulness, md5 is significantly cheaper.
-Rob
--
GPG key available at: <http://www.robertcollins.net/keys.txt>.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20070806/2696bc64/attachment.pgp
More information about the bazaar
mailing list