go test -run=NONE -bench=. -benchmem
goos: linux
goarch: amd64
pkg: hashtest
BenchmarkHash64/city-4 1427992 840 ns/op 0 B/op 0 allocs/op
BenchmarkHash64/farm-4 8033910 147 ns/op 0 B/op 0 allocs/op
BenchmarkHash64/fasthash-4 6717454 177 ns/op 0 B/op 0 allocs/op
BenchmarkHash64/fnv64a-4 974840 1118 ns/op 0 B/op 0 allocs/op
BenchmarkHash64/metro-4 10934460 106 ns/op 0 B/op 0 allocs/op
BenchmarkHash64/murmur3-4 3221816 367 ns/op 0 B/op 0 allocs/op
BenchmarkHash64/sip13-4 3452718 346 ns/op 0 B/op 0 allocs/op
BenchmarkHash64/stadtx-4 10871632 109 ns/op 0 B/op 0 allocs/op
BenchmarkHash64/wyhash-4 6283472 189 ns/op 0 B/op 0 allocs/op
BenchmarkHash64/xx-4 9261862 132 ns/op 0 B/op 0 allocs/op
BenchmarkHash64/xxh3-4 4198192 282 ns/op 0 B/op 0 allocs/op
PASS
ok hashbench 15.688s
Last active
November 25, 2019 13:15
-
-
Save dim/95ad5adf782f90bd67e2fcf5dbf2ec1f to your computer and use it in GitHub Desktop.
Go(lang) non-cryptographic hash benchmark
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
module hashbench | |
go 1.13 | |
require ( | |
github.com/bsm/go-x v0.8.1 | |
github.com/creachadair/cityhash v0.1.0 | |
github.com/dgryski/go-farm v0.0.0-20191112170834-c2139c5d712b | |
github.com/dgryski/go-metro v0.0.0-20180109044635-280f6062b5bc | |
github.com/dgryski/go-sip13 v0.0.0-20190329191031-25c5027a8c7b | |
github.com/dgryski/go-stadtx v0.0.0-20181220175827-101ddca05f0b | |
github.com/dgryski/go-wyhash v0.0.0-20190529011017-d4ee4020a781 | |
github.com/dgryski/go-xxh3 v0.0.0-20190317160639-1675ae87ac49 | |
github.com/opencoff/go-fasthash v0.0.0-20180406145558-aed761496075 | |
) |
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
github.com/bsm/go-x v0.8.1 h1:NMq4hSvTzJdsbz+da7Y22Eb18yKz6r5cUPf0VAhGCmM= | |
github.com/bsm/go-x v0.8.1/go.mod h1:zGSbXao0EJL4AOG9aZH6gan1wnKFY231nMgd9bFh3U8= | |
github.com/creachadair/cityhash v0.1.0 h1:rzSfISre5xT/EgbVvXBmsUJ58Hsrp8ccYMZVvc5uBmk= | |
github.com/creachadair/cityhash v0.1.0/go.mod h1:bYNmpea/cMZgL9Rjt+ZfDfjaT0hScMO6SSGV1DN5lEM= | |
github.com/dgryski/go-farm v0.0.0-20191112170834-c2139c5d712b h1:SeiGBzKrEtuDddnBABHkp4kq9sBGE9nuYmk6FPTg0zg= | |
github.com/dgryski/go-farm v0.0.0-20191112170834-c2139c5d712b/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw= | |
github.com/dgryski/go-metro v0.0.0-20180109044635-280f6062b5bc h1:8WFBn63wegobsYAX0YjD+8suexZDga5CctH4CCTx2+8= | |
github.com/dgryski/go-metro v0.0.0-20180109044635-280f6062b5bc/go.mod h1:c9O8+fpSOX1DM8cPNSkX/qsBWdkD4yd2dpciOWQjpBw= | |
github.com/dgryski/go-sip13 v0.0.0-20190329191031-25c5027a8c7b h1:Yqiad0+sloMPdd/0Fg22actpFx0dekpzt1xJmVNVkU0= | |
github.com/dgryski/go-sip13 v0.0.0-20190329191031-25c5027a8c7b/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no= | |
github.com/dgryski/go-stadtx v0.0.0-20181220175827-101ddca05f0b h1:YW8r3ofQ8j/EXptc9clMD3D4A/wm9ESkhI1gAcswos0= | |
github.com/dgryski/go-stadtx v0.0.0-20181220175827-101ddca05f0b/go.mod h1:egA8qbzCRr4cUpP+B1T3lgRGRSfRkcDDc0RId+RMI9I= | |
github.com/dgryski/go-wyhash v0.0.0-20190529011017-d4ee4020a781 h1:BBsOfFusANUigUWwpojg7Bxv9auJe2nrWYvSWHxOR+0= | |
github.com/dgryski/go-wyhash v0.0.0-20190529011017-d4ee4020a781/go.mod h1:/ENMIO1SQeJ5YQeUWWpbX8f+bS8INHrrhFjXgEqi4LA= | |
github.com/dgryski/go-xxh3 v0.0.0-20190317160639-1675ae87ac49 h1:E2VBGIi+PvI5Nl6ddS5W0RVtoJRfpRVaunUC8Q/NOJI= | |
github.com/dgryski/go-xxh3 v0.0.0-20190317160639-1675ae87ac49/go.mod h1:GEXsXVlzo0o2VPFcPwTUM6ssCHA4xn4fp8sdopBufVU= | |
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= | |
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= | |
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= | |
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= | |
github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= | |
github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= | |
github.com/opencoff/go-fasthash v0.0.0-20180406145558-aed761496075 h1:E6jK9PFTGb2trsAstgycRMavAki/W1NDF8aQ636Qf/k= | |
github.com/opencoff/go-fasthash v0.0.0-20180406145558-aed761496075/go.mod h1:MwRUIaK13/MmcsYPJVhMELsWvP1PQjTZeNn442GPpU4= | |
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= | |
golang.org/x/net v0.0.0-20181129055619-fae4c4e3ad76/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= | |
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= | |
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= | |
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= | |
golang.org/x/sys v0.0.0-20181128092732-4ed8d59d0b35/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= | |
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= | |
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | |
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | |
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= | |
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= | |
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= |
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
package hashbench_test | |
import ( | |
"math/rand" | |
"testing" | |
"github.com/bsm/go-x/hashx" | |
"github.com/creachadair/cityhash" | |
"github.com/dgryski/go-farm" | |
"github.com/dgryski/go-metro" | |
sip13 "github.com/dgryski/go-sip13" | |
"github.com/dgryski/go-stadtx" | |
"github.com/dgryski/go-wyhash" | |
"github.com/dgryski/go-xxh3" | |
"github.com/opencoff/go-fasthash" | |
) | |
func BenchmarkHash64(b *testing.B) { | |
rnd := rand.New(rand.NewSource(1)) | |
data := make([]byte, 1024) | |
if _, err := rnd.Read(data); err != nil { | |
b.Fatal(err) | |
} | |
ntimes := func(b *testing.B, cb func()) { | |
for i := 0; i < b.N; i++ { | |
cb() | |
} | |
} | |
b.Run("city", func(b *testing.B) { | |
ntimes(b, func() { cityhash.Hash64(data) }) | |
}) | |
b.Run("farm", func(b *testing.B) { | |
ntimes(b, func() { farm.Hash64(data) }) | |
}) | |
b.Run("fasthash", func(b *testing.B) { | |
ntimes(b, func() { fasthash.Hash64(0, data) }) | |
}) | |
b.Run("fnv64a", func(b *testing.B) { | |
ntimes(b, func() { hashx.Fnv64a(data) }) | |
}) | |
b.Run("metro", func(b *testing.B) { | |
ntimes(b, func() { metro.Hash64(data, 0) }) | |
}) | |
b.Run("murmur3", func(b *testing.B) { | |
ntimes(b, func() { hashx.MM64(data) }) | |
}) | |
b.Run("sip13", func(b *testing.B) { | |
ntimes(b, func() { sip13.Sum64(0, 1, data) }) | |
}) | |
b.Run("stadtx", func(b *testing.B) { | |
state := stadtx.SeedState([]uint64{0, 1}) | |
ntimes(b, func() { stadtx.Hash(&state, data) }) | |
}) | |
b.Run("wyhash", func(b *testing.B) { | |
ntimes(b, func() { wyhash.Hash(data, 0) }) | |
}) | |
b.Run("xx", func(b *testing.B) { | |
ntimes(b, func() { hashx.XX64(data, 0) }) | |
}) | |
b.Run("xxh3", func(b *testing.B) { | |
ntimes(b, func() { xxh3.XXH3_64bits(data) }) | |
}) | |
} |
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
default: bench | |
bench: | |
go test -run=NONE -bench=. -benchmem |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment