MCPcopy
hub / github.com/nextdns/nextdns / benchRistrettoGetHitParallel

Function benchRistrettoGetHitParallel

resolver/ristretto_metrics_bench_test.go:94–121  ·  view source on GitHub ↗
(b *testing.B, metrics bool)

Source from the content-addressed store, hash-verified

92}
93
94func benchRistrettoGetHitParallel(b *testing.B, metrics bool) {
95 c := newBenchCache(b, metrics)
96 defer c.Close()
97
98 const entries = 1 << 16
99 val := make([]byte, 256)
100 for i := range entries {
101 c.Set(uint64(i), val, int64(len(val)))
102 }
103 c.Wait()
104
105 b.ReportAllocs()
106 b.ResetTimer()
107
108 b.RunParallel(func(pb *testing.PB) {
109 // Give each worker a distinct offset so they don't all hammer the same key.
110 // strconv is a cheap way to get some per-goroutine entropy here.
111 var off uint64
112 if s := strconv.Itoa(int(b.N)); len(s) > 0 {
113 off = uint64(s[0])
114 }
115 var i uint64
116 for pb.Next() {
117 _, _ = c.Get((i + off) & (entries - 1))
118 i++
119 }
120 })
121}

Calls 5

newBenchCacheFunction · 0.85
NextMethod · 0.80
SetMethod · 0.65
GetMethod · 0.65
CloseMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…