MD5 to long?
Alex Martelli
aleax at aleax.it
Sat Apr 26 06:55:02 EDT 2003
Axel Grune wrote:
> Shoot me! eval works well;-)
>
> >>> longnumber = eval( '0x' + 'fd4cef7a4e607f1fcc920ad6329a6df2df99a4e8'
> >>> )
Sure, but calling long works MUCH better...:
[alex at lancelot Lib]$ python timeit.py
-s'x="fd4cef7a4e607f1fcc920ad6329a6df2df99a4e8"' 'ln=eval("0x"+x)'
10000 loops, best of 3: 31.4 usec per loop
[alex at lancelot Lib]$ python timeit.py
-s'x="fd4cef7a4e607f1fcc920ad6329a6df2df99a4e8"' 'ln=long(x,16)'
100000 loops, best of 3: 2.13 usec per loop
[alex at lancelot Lib]$
A speedup of 15 times as a result of using simpler and more direct
code seems to me to be worth pursuing.
Alex
More information about the Python-list
mailing list