Skip to content

Instantly share code, notes, and snippets.

@key
Last active April 28, 2017 02:36
Show Gist options
  • Save key/3964a0c5cb52989c0fbc3bcf3b4a834c to your computer and use it in GitHub Desktop.
Save key/3964a0c5cb52989c0fbc3bcf3b4a834c to your computer and use it in GitHub Desktop.
hash algorithm speed comparison ref: http://qiita.com/key/items/f614e90ef9ec5c4c839b
#!/usr/bin/env python
import timeit
def mmh3_test():
import mmh3
for i in range(0, 100000):
mmh3.hash(str(i))
def md5_test():
import hashlib
for i in range(0, 100000):
hashlib.md5(str(i)).hexdigest()
def sha1_test():
import hashlib
for i in range(0, 100000):
hashlib.sha1(str(i)).hexdigest()
if __name__ == '__main__':
import timeit
print(timeit.timeit("mmh3_test()", setup="from __main__ import mmh3_test", number=100))
print(timeit.timeit("md5_test()", setup="from __main__ import md5_test", number=100))
print(timeit.timeit("sha1_test()", setup="from __main__ import sha1_test", number=100))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment