Created
February 19, 2021 16:26
-
-
Save recoilme/9fd29c9f98f61da5daccc4d3454eb103 to your computer and use it in GitHub Desktop.
Benchmark murmur3(32) and xxHash64
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
package main_test | |
import ( | |
"strconv" | |
"testing" | |
"github.com/cespare/xxhash" | |
"github.com/spaolacci/murmur3" | |
) | |
func BenchmarkMurmur3(b *testing.B) { | |
buf := make([]byte, 8192) | |
for length := 1; length <= cap(buf); length *= 2 { | |
b.Run(strconv.Itoa(length), func(b *testing.B) { | |
buf = buf[:length] | |
b.SetBytes(int64(length)) | |
b.ReportAllocs() | |
b.ResetTimer() | |
for i := 0; i < b.N; i++ { | |
murmur3.Sum32(buf) | |
} | |
}) | |
} | |
} | |
func BenchmarkXXHash64(b *testing.B) { | |
buf := make([]byte, 8192) | |
d := xxhash.New() | |
for length := 1; length <= cap(buf); length *= 2 { | |
b.Run(strconv.Itoa(length), func(b *testing.B) { | |
buf = buf[:length] | |
b.SetBytes(int64(length)) | |
b.ReportAllocs() | |
b.ResetTimer() | |
for i := 0; i < b.N; i++ { | |
d.Write(buf) | |
d.Sum64() | |
} | |
}) | |
} | |
} | |
//results | |
``` | |
Running tool: /usr/local/go/bin/go test -benchmem -run=^$ -bench ^(BenchmarkMurmur3)$ | |
goos: darwin | |
goarch: amd64 | |
BenchmarkMurmur3/1-8 261194529 4.65 ns/op 215.26 MB/s 0 B/op 0 allocs/op | |
BenchmarkMurmur3/2-8 231687916 5.16 ns/op 387.90 MB/s 0 B/op 0 allocs/op | |
BenchmarkMurmur3/4-8 244568409 5.10 ns/op 784.66 MB/s 0 B/op 0 allocs/op | |
BenchmarkMurmur3/8-8 202498562 6.18 ns/op 1294.40 MB/s 0 B/op 0 allocs/op | |
BenchmarkMurmur3/16-8 155917936 7.89 ns/op 2027.11 MB/s 0 B/op 0 allocs/op | |
BenchmarkMurmur3/32-8 100000000 12.1 ns/op 2637.71 MB/s 0 B/op 0 allocs/op | |
BenchmarkMurmur3/64-8 61134163 19.9 ns/op 3220.25 MB/s 0 B/op 0 allocs/op | |
BenchmarkMurmur3/128-8 35080591 35.0 ns/op 3657.05 MB/s 0 B/op 0 allocs/op | |
BenchmarkMurmur3/256-8 16728124 69.4 ns/op 3691.12 MB/s 0 B/op 0 allocs/op | |
BenchmarkMurmur3/512-8 8880228 141 ns/op 3639.67 MB/s 0 B/op 0 allocs/op | |
BenchmarkMurmur3/1024-8 4368697 301 ns/op 3400.01 MB/s 0 B/op 0 allocs/op | |
BenchmarkMurmur3/2048-8 2092203 543 ns/op 3771.25 MB/s 0 B/op 0 allocs/op | |
BenchmarkMurmur3/4096-8 1090856 1060 ns/op 3865.08 MB/s 0 B/op 0 allocs/op | |
BenchmarkMurmur3/8192-8 574178 2254 ns/op 3634.05 MB/s 0 B/op 0 allocs/op | |
PASS | |
Running tool: /usr/local/go/bin/go test -benchmem -run=^$ -bench ^(BenchmarkXXHash64)$ | |
goos: darwin | |
goarch: amd64 | |
BenchmarkXXHash64/1-8 76161969 14.2 ns/op 70.43 MB/s 0 B/op 0 allocs/op | |
BenchmarkXXHash64/2-8 81727155 14.4 ns/op 139.15 MB/s 0 B/op 0 allocs/op | |
BenchmarkXXHash64/4-8 70088184 17.1 ns/op 233.93 MB/s 0 B/op 0 allocs/op | |
BenchmarkXXHash64/8-8 63670485 17.5 ns/op 458.18 MB/s 0 B/op 0 allocs/op | |
BenchmarkXXHash64/16-8 55560175 20.2 ns/op 790.71 MB/s 0 B/op 0 allocs/op | |
BenchmarkXXHash64/32-8 47499522 24.8 ns/op 1288.36 MB/s 0 B/op 0 allocs/op | |
BenchmarkXXHash64/64-8 38354180 29.7 ns/op 2151.46 MB/s 0 B/op 0 allocs/op | |
BenchmarkXXHash64/128-8 35680100 32.6 ns/op 3923.77 MB/s 0 B/op 0 allocs/op | |
BenchmarkXXHash64/256-8 28122490 42.5 ns/op 6028.58 MB/s 0 B/op 0 allocs/op | |
BenchmarkXXHash64/512-8 22367116 55.1 ns/op 9289.50 MB/s 0 B/op 0 allocs/op | |
BenchmarkXXHash64/1024-8 13504466 86.0 ns/op 11909.89 MB/s 0 B/op 0 allocs/op | |
BenchmarkXXHash64/2048-8 8672275 143 ns/op 14356.78 MB/s 0 B/op 0 allocs/op | |
BenchmarkXXHash64/4096-8 4205932 263 ns/op 15554.23 MB/s 0 B/op 0 allocs/op | |
BenchmarkXXHash64/8192-8 2297762 502 ns/op 16325.62 MB/s 0 B/op 0 allocs/op | |
PASS | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment