-
-
Save OneOfOne/7661de2ba606661d79ae91a9fcbc64b3 to your computer and use it in GitHub Desktop.
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
// .... 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