(Sync.map)
(b *testing.B)
| 189 | |
| 190 | // (Sync.map) |
| 191 | func 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) |
| 221 | func BenchmarkGetKey_ChubbyGo_ConcurrentMap(b *testing.B){ |
nothing calls this directly
no outgoing calls
no test coverage detected