1
0
mirror of https://github.com/charlienet/go-mixed.git synced 2025-07-18 08:32:40 +08:00
This commit is contained in:
2022-03-28 17:35:58 +08:00
parent abeabeeb61
commit a5fb792dcf
4 changed files with 158 additions and 12 deletions

View File

@ -29,3 +29,31 @@ func TestMapCount(t *testing.T) {
mm["a"] = "b"
assert.Equal(t, 1, len(mm))
}
func BenchmarkMap(b *testing.B) {
b.Run("RWLock", func(b *testing.B) {
m := generics.NewRWLockMap[string, string]()
doBenchamark(b, m)
})
b.Run("ConcurrnetMap", func(b *testing.B) {
doBenchamark(b, generics.NewConcurrnetMap[string, string]())
})
}
func doBenchamark(b *testing.B, m generics.Map[string, string]) {
var k = "abc"
var v = "bcd"
b.RunParallel(func(p *testing.PB) {
for p.Next() {
m.Set(k, v)
m.Get(k)
m.Get(k)
m.Get(k)
m.Delete(k)
}
})
}