Last active
September 10, 2017 03:46
-
-
Save deckarep/694ffb47b1eaa77c6c3e6ce75160bd7e to your computer and use it in GitHub Desktop.
Benchmark sync.Map vs regular map for Stores
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
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