cespare / mph

Minimal perfect hashing in Go
MIT License
72 stars 12 forks source link

builtin map faster then Lookup #1

Closed chennqqi closed 6 years ago

chennqqi commented 6 years ago

goos: linux goarch: amd64 pkg: github.com/alecthomas/mph BenchmarkBuiltinMap-40 10000000 144 ns/op BenchmarkCHD-40 10000000 205 ns/op

cespare commented 6 years ago

Those benchmarks don't come from this package, they come from github.com/alecthomas/mph.

My package also has benchmarks that compare it against the stdlib map and the last time I ran them, mph was faster in that benchmark, though I haven't run it recently.

cespare commented 6 years ago

FWIW, the MPH implementation in this package does seem faster than a map[string]uint32, though the gap has closed somewhat:

$ go test -bench Table -benchtime 10s
goos: linux
goarch: amd64
pkg: github.com/cespare/mph
BenchmarkTable          300000000               48.6 ns/op
BenchmarkTableMap       200000000               67.6 ns/op