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

Function BenchmarkGetKey_SyncMap

MapPerformanceTest/test_test.go:191–218  ·  view source on GitHub ↗

(Sync.map)

(b *testing.B)

Source from the content-addressed store, hash-verified

189
190// (Sync.map)
191func BenchmarkGetKey_SyncMap(b *testing.B){
192 syncMap := &sync.Map{}
193
194 groups := sync.WaitGroup{}
195 groups.Add(ThreadNumber)
196
197 rand.Seed(time.Now().Unix())
198 // 可能产生(64,128)个键
199 KeyNumber := rand.Intn(63)
200 KeyNumber += 64
201 for i:=0; i<KeyNumber; i++{
202 TempWord := "x " + strconv.Itoa(i) + " y"
203 syncMap.Store(TempWord, "lizhaolong")
204 }
205
206 b.ResetTimer()
207
208 for j:=0; j < ThreadNumber; j++{
209 go func(){
210 for i := 0; i < b.N; i++ {
211 TempWord := "x " + strconv.Itoa(i%KeyNumber) + " y"
212 syncMap.Load(TempWord)
213 }
214 groups.Done()
215 }()
216 }
217 groups.Wait()
218}
219
220// (chubbyGoMap.ConcurrentMap)
221func BenchmarkGetKey_ChubbyGo_ConcurrentMap(b *testing.B){

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected