(b *testing.B)
| 260 | } |
| 261 | |
| 262 | func BenchmarkPutAndOverflow(b *testing.B) { |
| 263 | const maxCacheSize = 100 |
| 264 | |
| 265 | setupCache := func(cacheType cacheType, warmupCache bool) (cache Cache) { |
| 266 | if cacheType == randReplKeyCache { |
| 267 | cache = NewRandReplKeyCache(maxCacheSize) |
| 268 | } else if cacheType == noReplKeyCache { |
| 269 | cache = NewNoReplKeyCache(maxCacheSize) |
| 270 | } |
| 271 | if warmupCache { |
| 272 | for i := 0; i < maxCacheSize; i++ { |
| 273 | cache.Put(randKey(math.MaxUint32)) |
| 274 | } |
| 275 | } |
| 276 | return cache |
| 277 | } |
| 278 | |
| 279 | benchmarks := []struct { |
| 280 | name string |
| 281 | cacheType cacheType |
| 282 | warmupCache bool |
| 283 | runParallel bool |
| 284 | }{ |
| 285 | {"FillRandReplKeyCache", randReplKeyCache, false, false}, |
| 286 | {"FillNoReplKeyCache", noReplKeyCache, false, false}, |
| 287 | |
| 288 | {"RefillRandReplKeyCache", randReplKeyCache, true, false}, |
| 289 | {"RefillNoReplKeyCache", noReplKeyCache, true, false}, |
| 290 | |
| 291 | {"ParallelFillRandReplKeyCache", randReplKeyCache, false, true}, |
| 292 | {"ParallelFillNoReplKeyCache", noReplKeyCache, false, true}, |
| 293 | |
| 294 | {"ParallelRefillRandReplKeyCache", randReplKeyCache, true, true}, |
| 295 | {"ParallelRefillNoReplKeyCache", noReplKeyCache, true, true}, |
| 296 | } |
| 297 | for _, bm := range benchmarks { |
| 298 | b.Run(bm.name, func(b *testing.B) { |
| 299 | cache := setupCache(bm.cacheType, bm.warmupCache) |
| 300 | b.ResetTimer() |
| 301 | if bm.runParallel { |
| 302 | b.RunParallel(func(pb *testing.PB) { |
| 303 | b.ReportAllocs() |
| 304 | for pb.Next() { |
| 305 | cache.Put(randKey(math.MaxUint32)) |
| 306 | } |
| 307 | }) |
| 308 | } else { |
| 309 | b.Run(bm.name, func(b *testing.B) { |
| 310 | b.ReportAllocs() |
| 311 | for i := 0; i < b.N; i++ { |
| 312 | cache.Put(randKey(math.MaxUint32)) |
| 313 | } |
| 314 | }) |
| 315 | } |
| 316 | }) |
| 317 | } |
| 318 | } |
| 319 |
nothing calls this directly
no test coverage detected