Skip to content

Instantly share code, notes, and snippets.

@deckarep
Last active September 10, 2017 03:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deckarep/694ffb47b1eaa77c6c3e6ce75160bd7e to your computer and use it in GitHub Desktop.
Save deckarep/694ffb47b1eaa77c6c3e6ce75160bd7e to your computer and use it in GitHub Desktop.
Benchmark sync.Map vs regular map for Stores
func nrand(n int) []int {
i := make([]int, n)
for ind := range i {
i[ind] = rand.Int()
}
return i
}
func BenchmarkStoreRegular(b *testing.B) {
nums := nrand(b.N)
rm := NewRegularIntMap()
b.ResetTimer()
for _, v := range nums {
rm.Store(v, v)
}
}
func BenchmarkStoreSync(b *testing.B) {
nums := nrand(b.N)
var sm sync.Map
b.ResetTimer()
for _, v := range nums {
sm.Store(v, v)
}
}
/*
BenchmarkStoreRegular-32 5000000 319 ns/op
BenchmarkStoreSync-32 1000000 1146 ns/op
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment