Last active
January 6, 2023 16:20
-
-
Save baojie/9202681 to your computer and use it in GitHub Desktop.
python hash function test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import timeit | |
import random | |
import string | |
data = ''.join([random.choice(string.ascii_letters) for x in range(1024*1024)]) | |
print "md5", | |
print timeit.timeit('hashlib.md5().update(data)', number=10000, setup='import hashlib; data="%s"' % data) | |
print "sha1", | |
print timeit.timeit('hashlib.sha1().update(data)', number=10000, setup='import hashlib; data="%s"' % data) | |
print "sha256", | |
print timeit.timeit('hashlib.sha256().update(data)', number=10000, setup='import hashlib; data="%s"' % data) | |
print "sha512", | |
print timeit.timeit('hashlib.sha512().update(data)', number=10000, setup='import hashlib; data="%s"' % data) | |
print "mmh3", | |
print timeit.timeit('mmh3.hash128(data)', number=10000, setup='import mmh3; data="%s"' % data) | |
print "smhasher", | |
print timeit.timeit('smhasher.murmur3_x86_128(data)', number=10000, setup='import smhasher; data="%s"' % data) | |
print "hashxx" | |
print timeit.timeit('pyhashxx.hashxx(data)', number=10000, setup='import pyhashxx; data="%s"' % data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
python -m timeit "import hashlib; hashlib.md5().update('foo')" | |
# 1000000 loops, best of 3: 1.07 usec per loop | |
python -m timeit "import hashlib; hashlib.sha1().update('foo')" | |
# 1000000 loops, best of 3: 1.09 usec per loop | |
python -m timeit "import hashlib; hashlib.sha256().update('foo')" | |
# 1000000 loops, best of 3: 1.2 usec per loop | |
python -m timeit "import hashlib; hashlib.sha512().update('foo')" | |
# 1000000 loops, best of 3: 1.17 usec per loop | |
python -m timeit "import mmh3; mmh3.hash128('foo')" | |
# 1000000 loops, best of 3: 0.602 usec per loop | |
python -m timeit "import smhasher; smhasher.murmur3_x86_128('foo')" | |
# 1000000 loops, best of 3: 0.614 usec per loop | |
python -m timeit "import pyhashxx; pyhashxx.hashxx('foo')" | |
# 1000000 loops, best of 3: 0.513 usec per loop | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment