Skip to content

Instantly share code, notes, and snippets.

@OneOfOne
Created July 7, 2017 17:57
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 OneOfOne/7661de2ba606661d79ae91a9fcbc64b3 to your computer and use it in GitHub Desktop.
Save OneOfOne/7661de2ba606661d79ae91a9fcbc64b3 to your computer and use it in GitHub Desktop.
// .... modified *_test to use an interface
func BenchmarkLoadOrStoreAddOnValue(b *testing.B) {
benchMap(b, bench{
setup: func(b *testing.B, m mapInterface) {
if _, ok := m.(*DeepCopyMap); ok {
b.Skip("DeepCopyMap has quadratic running time.")
}
},
perG: func(b *testing.B, pb *testing.PB, i int, m mapInterface) {
for ; pb.Next(); i++ {
v, _ := m.LoadOrStore(i%10, new(uint64))
atomic.AddUint64(v.(*uint64), 1)
}
},
})
}
func BenchmarkLoadOrStoreFnAddOnValue(b *testing.B) {
fn := func() interface{} { return new(uint64) }
benchMap(b, bench{
setup: func(b *testing.B, m mapInterface) {
if _, ok := m.(*DeepCopyMap); ok {
b.Skip("DeepCopyMap has quadratic running time.")
}
},
perG: func(b *testing.B, pb *testing.PB, i int, m mapInterface) {
for ; pb.Next(); i++ {
v, _ := m.LoadOrStoreFn(i%10, fn)
atomic.AddUint64(v.(*uint64), 1)
}
},
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment