======================================================================== Benchmark Code ========================================================================
(b *testing.B, cache Cache, keys [][]byte, pctWrites uint64)
| 327 | //======================================================================== |
| 328 | |
| 329 | func runCacheBenchmark(b *testing.B, cache Cache, keys [][]byte, pctWrites uint64) { |
| 330 | b.ReportAllocs() |
| 331 | |
| 332 | size := len(keys) |
| 333 | mask := size - 1 |
| 334 | rc := uint64(0) |
| 335 | |
| 336 | // initialize cache |
| 337 | for i := 0; i < size; i++ { |
| 338 | _ = cache.Set(keys[i], []byte("data")) |
| 339 | } |
| 340 | |
| 341 | b.ResetTimer() |
| 342 | b.RunParallel(func(pb *testing.PB) { |
| 343 | index := rand.Int() & mask |
| 344 | mc := atomic.AddUint64(&rc, 1) |
| 345 | |
| 346 | if pctWrites*mc/100 != pctWrites*(mc-1)/100 { |
| 347 | for pb.Next() { |
| 348 | _ = cache.Set(keys[index&mask], []byte("data")) |
| 349 | index = index + 1 |
| 350 | } |
| 351 | } else { |
| 352 | for pb.Next() { |
| 353 | _, _ = cache.Get(keys[index&mask]) |
| 354 | index = index + 1 |
| 355 | } |
| 356 | } |
| 357 | }) |
| 358 | } |
| 359 | |
| 360 | func BenchmarkCaches(b *testing.B) { |
| 361 | zipfList := zipfKeyList() |
no test coverage detected