Skip to content

Instantly share code, notes, and snippets.

@deckarep
Last active September 10, 2017 03:47
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/700ba8656b1a0c18a09c6a1f1e593f28 to your computer and use it in GitHub Desktop.
Save deckarep/700ba8656b1a0c18a09c6a1f1e593f28 to your computer and use it in GitHub Desktop.
Benchmark sync.Map vs regular RWMutex map
func BenchmarkDeleteRegular(b *testing.B) {
nums := nrand(b.N)
rm := NewRegularIntMap()
for _, v := range nums {
rm.Store(v, v)
}
b.ResetTimer()
for _, v := range nums {
rm.Delete(v)
}
}
func BenchmarkDeleteSync(b *testing.B) {
nums := nrand(b.N)
var sm sync.Map
for _, v := range nums {
sm.Store(v, v)
}
b.ResetTimer()
for _, v := range nums {
sm.Delete(v)
}
}
/*
BenchmarkDeleteRegular-32 10000000 238 ns/op
BenchmarkDeleteSync-32 5000000 393 ns/op
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment