MCPcopy Create free account
hub / github.com/Super-long/ChubbyGo / BenchmarkGetKey_ConcurrentMap

Function BenchmarkGetKey_ConcurrentMap

MapPerformanceTest/test_test.go:161–188  ·  view source on GitHub ↗

(ConcurrentMap)

(b *testing.B)

Source from the content-addressed store, hash-verified

159
160//(ConcurrentMap)
161func BenchmarkGetKey_ConcurrentMap(b *testing.B){
162 Map := BaseServer.NewConcurrentMap()
163
164 groups := sync.WaitGroup{}
165 groups.Add(ThreadNumber)
166
167 rand.Seed(time.Now().Unix())
168 // 可能产生(64,128)个键
169 KeyNumber := rand.Intn(63)
170 KeyNumber += 64
171 for i:=0; i<KeyNumber; i++{
172 TempWord := "x " + strconv.Itoa(i) + " y"
173 Map.Set(TempWord, "lizhaolong")
174 }
175
176 b.ResetTimer()
177
178 for j:=0; j < ThreadNumber; j++{
179 go func(){
180 for i := 0; i < b.N; i++ {
181 TempWord := "x " + strconv.Itoa(i%KeyNumber) + " y"
182 Map.Get(TempWord)
183 }
184 groups.Done()
185 }()
186 }
187 groups.Wait()
188}
189
190// (Sync.map)
191func BenchmarkGetKey_SyncMap(b *testing.B){

Callers

nothing calls this directly

Calls 2

SetMethod · 0.80
GetMethod · 0.45

Tested by

no test coverage detected