I was worried about the speed of the hash function, so make a note.
Compare the classic (?) Md5 with sha1 and murmurhash3. Execute 100 sets of 100,000 times each and compare the results. The machine I ran was a MacBook Pro Late 2016 with an Intel Core i7 2.6GHz Quad Core.
Hash function | time(s) |
---|---|
md5 | 12.7691998482 |
sha1 | 13.9324979782 |
murmurhash3 | 2.75016593933 |
This is the code for comparison.
#!/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))
Recommended Posts