Last active
December 20, 2015 18:58
-
-
Save kgriffs/6179456 to your computer and use it in GitHub Desktop.
Benchmark results from testing several python hash libs against str.__hash(), on my MBP Retina, 15-inch, Early 2013. This was run under Python 2.7. using various python hash functions. MurmurHash3 was used for the Murmur tests.
This file contains hidden or 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
Note: "memo" is just testing constructing a string, to prove | |
that strings are not hashed at create time, but memoized with | |
__hash__(). The functions construct new strings each time, | |
with some variant of: | |
'24058098:33d2a96e-ffad-11e2-b14b-8acd18156acf' * m | |
Where m is passed into the test function. | |
--------------------------------------------- | |
In [151]: %timeit test_memo() | |
1000000 loops, best of 3: 280 ns per loop | |
In [152]: %timeit test_builtin() | |
1000000 loops, best of 3: 276 ns per loop | |
In [153]: %timeit test_murmur() | |
1000000 loops, best of 3: 386 ns per loop | |
In [154]: %timeit test_xx() | |
1000000 loops, best of 3: 358 ns per loop | |
In [155]: %timeit test_memo(2) | |
1000000 loops, best of 3: 325 ns per loop | |
In [156]: %timeit test_builtin(2) | |
1000000 loops, best of 3: 414 ns per loop | |
In [157]: %timeit test_murmur(2) | |
1000000 loops, best of 3: 441 ns per loop | |
In [158]: %timeit test_xx(2) | |
1000000 loops, best of 3: 409 ns per loop | |
In [159]: %timeit test_memo(5) | |
1000000 loops, best of 3: 442 ns per loop | |
In [160]: %timeit test_builtin(5) | |
1000000 loops, best of 3: 700 ns per loop | |
In [161]: %timeit test_murmur(5) | |
1000000 loops, best of 3: 655 ns per loop | |
In [162]: %timeit test_xx(5) | |
1000000 loops, best of 3: 571 ns per loop | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment