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

Function Benchmark100Fields

logger_bench_test.go:262–285  ·  view source on GitHub ↗
(b *testing.B)

Source from the content-addressed store, hash-verified

260}
261
262func Benchmark100Fields(b *testing.B) {
263 const batchSize = 50
264 logger := New(zapcore.NewCore(
265 zapcore.NewJSONEncoder(NewProductionConfig().EncoderConfig),
266 &ztest.Discarder{},
267 DebugLevel,
268 ))
269
270 // Don't include allocating these helper slices in the benchmark. Since
271 // access to them isn't synchronized, we can't run the benchmark in
272 // parallel.
273 first := make([]Field, batchSize)
274 second := make([]Field, batchSize)
275 b.ResetTimer()
276
277 for i := 0; i < b.N; i++ {
278 for i := 0; i < batchSize; i++ {
279 // We're duplicating keys, but that doesn't affect performance.
280 first[i] = Int("foo", i)
281 second[i] = Int("foo", i+batchSize)
282 }
283 logger.With(first...).Info("Child loggers with lots of context.", second...)
284 }
285}
286
287func BenchmarkAny(b *testing.B) {
288 key := "some-long-string-longer-than-16"

Callers

nothing calls this directly

Calls 7

NewCoreFunction · 0.92
NewJSONEncoderFunction · 0.92
NewProductionConfigFunction · 0.85
IntFunction · 0.85
NewFunction · 0.70
WithMethod · 0.65
InfoMethod · 0.45

Tested by

no test coverage detected