MCPcopy
hub / github.com/uber-go/zap / BenchmarkSampler_CheckWithHook

Function BenchmarkSampler_CheckWithHook

zapcore/sampler_bench_test.go:249–287  ·  view source on GitHub ↗
(b *testing.B)

Source from the content-addressed store, hash-verified

247}
248
249func BenchmarkSampler_CheckWithHook(b *testing.B) {
250 hook, dropped, sampled := makeSamplerCountingHook()
251 for _, keys := range counterTestCases {
252 b.Run(fmt.Sprintf("%v keys", len(keys)), func(b *testing.B) {
253 fac := NewSamplerWithOptions(
254 NewCore(
255 NewJSONEncoder(testEncoderConfig()),
256 &ztest.Discarder{},
257 DebugLevel,
258 ),
259 time.Millisecond,
260 1,
261 1000,
262 SamplerHook(hook),
263 )
264 b.ResetTimer()
265 b.RunParallel(func(pb *testing.PB) {
266 i := 0
267 for pb.Next() {
268 ent := Entry{
269 Level: DebugLevel + Level(i%4),
270 Message: keys[i],
271 }
272 _ = fac.Check(ent, nil)
273 i++
274 if n := len(keys); i >= n {
275 i -= n
276 }
277 }
278 })
279 // We expect to see 1000 dropped messages for every sampled per settings,
280 // with a delta due to less 1000 messages getting dropped after initial one
281 // is sampled.
282 assert.Greater(b, dropped.Load()/1000, sampled.Load()-1000)
283 dropped.Store(0)
284 sampled.Store(0)
285 })
286 }
287}

Callers

nothing calls this directly

Calls 9

NewSamplerWithOptionsFunction · 0.85
NewCoreFunction · 0.85
NewJSONEncoderFunction · 0.85
testEncoderConfigFunction · 0.85
SamplerHookFunction · 0.85
NextMethod · 0.80
makeSamplerCountingHookFunction · 0.70
LevelTypeAlias · 0.70
CheckMethod · 0.65

Tested by

no test coverage detected