Skip to content

Instantly share code, notes, and snippets.

@derekcollison
Created October 29, 2012 22:32
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save derekcollison/3976970 to your computer and use it in GitHub Desktop.
Save derekcollison/3976970 to your computer and use it in GitHub Desktop.
Fast Hash Algorithms in Go
I have done some more work on creating very fast hash algorithms in Go for small (3-8) and medium (16-32) size keys. Below are the current results.
NOTE: I used SetBytes(1) to give quick estimate of ops/sec
2012 MacbookAir 11" i7 2Ghz
================
OSX - Mountain Lion
Go version go1.0.3
================
go test --bench="." -gcflags="-B"
Benchmark_Bernstein_SmallKey 200000000 9.17 ns/op 109.03 MB/s
Benchmark_Murmur3___SmallKey 200000000 9.68 ns/op 103.27 MB/s
Benchmark_FNV1A_____SmallKey 200000000 9.21 ns/op 108.58 MB/s
Benchmark_Meiyan____SmallKey 500000000 6.34 ns/op 157.82 MB/s
Benchmark_Jesteress_SmallKey 500000000 6.37 ns/op 157.01 MB/s
Benchmark_Yorikke___SmallKey 500000000 6.98 ns/op 143.34 MB/s
Benchmark_Bernstein___MedKey 50000000 53.4 ns/op 18.71 MB/s
Benchmark_Murmur3_____MedKey 100000000 29.8 ns/op 33.56 MB/s
Benchmark_FNV1A_______MedKey 50000000 52.6 ns/op 19.02 MB/s
Benchmark_Meiyan______MedKey 200000000 8.84 ns/op 113.14 MB/s
Benchmark_Jesteress___MedKey 200000000 7.94 ns/op 125.90 MB/s
Benchmark_Yorikke_____MedKey 200000000 9.48 ns/op 105.50 MB/s
================
Ubunutu 12.10
Go version go1.0.3
gcc version 4.7.2 (Ubuntu/Linaro 4.7.2-4precise1)
================
go test --bench="." -gcflags="-B"
Benchmark_Bernstein_SmallKey 200000000 9.90 ns/op 101.06 MB/s
Benchmark_Murmur3___SmallKey 100000000 10.1 ns/op 98.96 MB/s
Benchmark_FNV1A_____SmallKey 200000000 9.29 ns/op 107.59 MB/s
Benchmark_Meiyan____SmallKey 500000000 6.15 ns/op 162.50 MB/s
Benchmark_Jesteress_SmallKey 500000000 6.78 ns/op 147.58 MB/s
Benchmark_Yorikke___SmallKey 500000000 7.17 ns/op 139.49 MB/s
Benchmark_Bernstein___MedKey 50000000 55.0 ns/op 18.18 MB/s
Benchmark_Murmur3_____MedKey 50000000 30.2 ns/op 33.13 MB/s
Benchmark_FNV1A_______MedKey 50000000 56.0 ns/op 17.86 MB/s
Benchmark_Meiyan______MedKey 200000000 9.14 ns/op 109.43 MB/s
Benchmark_Jesteress___MedKey 200000000 8.25 ns/op 121.24 MB/s
Benchmark_Yorikke_____MedKey 200000000 9.72 ns/op 102.91 MB/s
go test --bench="." -compiler gccgo -gccgoflags="-O2" -gcflags="-B"
Benchmark_Bernstein_SmallKey 500000000 4.70 ns/op 212.97 MB/s
Benchmark_Murmur3___SmallKey 200000000 8.18 ns/op 122.21 MB/s
Benchmark_FNV1A_____SmallKey 500000000 5.18 ns/op 193.17 MB/s
Benchmark_Meiyan____SmallKey 500000000 6.21 ns/op 161.13 MB/s
Benchmark_Jesteress_SmallKey 500000000 5.51 ns/op 181.38 MB/s
Benchmark_Yorikke___SmallKey 500000000 7.13 ns/op 140.19 MB/s
Benchmark_Bernstein___MedKey 100000000 27.8 ns/op 35.98 MB/s
Benchmark_Murmur3_____MedKey 100000000 19.1 ns/op 52.46 MB/s
Benchmark_FNV1A_______MedKey 50000000 34.7 ns/op 28.79 MB/s
Benchmark_Meiyan______MedKey 500000000 7.24 ns/op 138.10 MB/s
Benchmark_Jesteress___MedKey 500000000 6.58 ns/op 151.97 MB/s
Benchmark_Yorikke_____MedKey 200000000 9.08 ns/op 110.17 MB/s
go test --bench="." -compiler gccgo -gccgoflags="-O3" -gcflags="-B"
Benchmark_Bernstein_SmallKey 2000000000 1.80 ns/op 555.22 MB/s
Benchmark_Murmur3___SmallKey 200000000 8.07 ns/op 123.86 MB/s
Benchmark_FNV1A_____SmallKey 2000000000 1.89 ns/op 528.93 MB/s
Benchmark_Meiyan____SmallKey 500000000 6.20 ns/op 161.36 MB/s
Benchmark_Jesteress_SmallKey 500000000 5.47 ns/op 182.76 MB/s
Benchmark_Yorikke___SmallKey 500000000 7.11 ns/op 140.58 MB/s
Benchmark_Bernstein___MedKey 100000000 20.3 ns/op 49.18 MB/s
Benchmark_Murmur3_____MedKey 100000000 19.0 ns/op 52.58 MB/s
Benchmark_FNV1A_______MedKey 100000000 20.3 ns/op 49.35 MB/s
Benchmark_Meiyan______MedKey 500000000 6.99 ns/op 143.00 MB/s
Benchmark_Jesteress___MedKey 500000000 6.44 ns/op 155.23 MB/s
Benchmark_Yorikke_____MedKey 200000000 9.01 ns/op 110.98 MB/s
@derekcollison
Copy link
Author

If some of the algorithms do not look familiar, look here: http://www.sanmayce.com/Fastest_Hash/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment