Skip to content

Instantly share code, notes, and snippets.

@OneOfOne OneOfOne/bench.go Secret
Created Jul 7, 2017

Embed
What would you like to do?
// .... 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
You can’t perform that action at this time.