MCPcopy Create free account
hub / github.com/dgraph-io/dgraph-benchmarks / runCacheBenchmark

Function runCacheBenchmark

cachebench/cache_bench_test.go:329–358  ·  view source on GitHub ↗

======================================================================== Benchmark Code ========================================================================

(b *testing.B, cache Cache, keys [][]byte, pctWrites uint64)

Source from the content-addressed store, hash-verified

327//========================================================================
328
329func 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
360func BenchmarkCaches(b *testing.B) {
361 zipfList := zipfKeyList()

Callers 1

BenchmarkCachesFunction · 0.85

Calls 3

NextMethod · 0.80
SetMethod · 0.65
GetMethod · 0.65

Tested by

no test coverage detected