MCPcopy
hub / github.com/grpc/grpc-go / benchmarkIncrementUint64Map

Function benchmarkIncrementUint64Map

benchmark/primitives/syncmap_test.go:109–153  ·  view source on GitHub ↗
(b *testing.B, f func() incrementUint64Map)

Source from the content-addressed store, hash-verified

107}
108
109func benchmarkIncrementUint64Map(b *testing.B, f func() incrementUint64Map) {
110 const cat = "cat"
111 benches := []struct {
112 name string
113 goroutineCount int
114 }{
115 {
116 name: " 1",
117 goroutineCount: 1,
118 },
119 {
120 name: " 10",
121 goroutineCount: 10,
122 },
123 {
124 name: " 100",
125 goroutineCount: 100,
126 },
127 {
128 name: "1000",
129 goroutineCount: 1000,
130 },
131 }
132 for _, bb := range benches {
133 b.Run(bb.name, func(b *testing.B) {
134 m := f()
135 var wg sync.WaitGroup
136 wg.Add(bb.goroutineCount)
137 b.ResetTimer()
138 for i := 0; i < bb.goroutineCount; i++ {
139 go func() {
140 for j := 0; j < b.N; j++ {
141 m.increment(cat)
142 }
143 wg.Done()
144 }()
145 }
146 wg.Wait()
147 b.StopTimer()
148 if m.result(cat) != uint64(bb.goroutineCount*b.N) {
149 b.Fatalf("result is %d, want %d", m.result(cat), b.N)
150 }
151 })
152 }
153}
154
155func BenchmarkMapWithSyncMutexContention(b *testing.B) {
156 benchmarkIncrementUint64Map(b, newMapWithLock)

Calls 6

WaitMethod · 0.80
AddMethod · 0.65
incrementMethod · 0.65
resultMethod · 0.65
FatalfMethod · 0.65
DoneMethod · 0.45

Tested by

no test coverage detected