Skip to content

Instantly share code, notes, and snippets.

@mrknmc
Last active August 29, 2015 14:08
Show Gist options
  • Save mrknmc/1992443dc5a7b26c24c6 to your computer and use it in GitHub Desktop.
Save mrknmc/1992443dc5a7b26c24c6 to your computer and use it in GitHub Desktop.
Python hashing functions performance
>>> def md5(s):
... return hashlib.md5(s).hexdigest()
...
>>> def sha1(s):
... return hashlib.sha1(s).hexdigest()
...
>>> def sha256(s):
... return hashlib.sha256(s).hexdigest()
...
>>> def sha512(s):
... return hashlib.sha512(s).hexdigest()
...
>>> tmd5 = timeit.Timer("md5('asdf' * 100)", "from __main__ import md5")
>>> t1 = timeit.Timer("sha1('asdf' * 100)", "from __main__ import sha1")
>>> t256 = timeit.Timer("sha256('asdf' * 100)", "from __main__ import sha256")
>>> t512 = timeit.Timer("sha512('asdf' * 100)", "from __main__ import sha512")
>>> tmd5.timeit()
3.7703371047973633
>>> t1.timeit()
3.9217898845672607
>>> t256.timeit()
5.839659929275513
>>> t512.timeit()
5.449558973312378
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment