Go Benchmark Map vs Slice
Update Github user Kuba left this comment in the form of a github issue back when my blog was hosted on github pages: https://github.com/miketmoore/miketmoore.github.io/issues/1. I think this is a great example of how inviting and helpful the Go community can be. Kuba pointed out a problem with my benchmark and how slices are actually fast!
A quick benchmark comparing performance of writing to a map versus appending to a slice. I also created two separate benchmarks to compare setting
uint8 in the maps. It looks like the map with the
uint8 values is the fastest option.
Mon Dec 17 09:37:28 > go test -bench=. -benchtime=20s goos: darwin goarch: amd64 pkg: github.com/miketmoore/mapsvsslicesperf BenchmarkMapBool-8 100000000 208 ns/op BenchmarkMapUint8-8 200000000 180 ns/op BenchmarkSlice-8 20000000 1967 ns/op PASS ok github.com/miketmoore/mapsvsslicesperf 118.673s