1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
// Copyright 2023 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package zerolog_benchmarks
import (
"io"
"testing"
"github.com/rs/zerolog"
slogbench "golang.org/x/exp/slog/benchmarks"
)
// Keep in sync (same names and behavior) as the
// benchmarks in the parent directory.
func BenchmarkAttrs(b *testing.B) {
logger := zerolog.New(zerolog.SyncWriter(io.Discard)).With().Timestamp().Logger()
b.Run("JSON discard", func(b *testing.B) {
b.Run("5 args", func(b *testing.B) {
b.ReportAllocs()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
logger.Info().
Str("string", slogbench.TestString).
Int("status", slogbench.TestInt).
Dur("duration", slogbench.TestDuration).
Time("time", slogbench.TestTime).
Err(slogbench.TestError).
Msg(slogbench.TestMessage)
}
})
})
b.Run("10 args", func(b *testing.B) {
b.ReportAllocs()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
logger.Info().
Str("string", slogbench.TestString).
Int("status", slogbench.TestInt).
Dur("duration", slogbench.TestDuration).
Time("time", slogbench.TestTime).
Err(slogbench.TestError).
Str("string", slogbench.TestString).
Int("status", slogbench.TestInt).
Dur("duration", slogbench.TestDuration).
Time("time", slogbench.TestTime).
Err(slogbench.TestError).
Msg(slogbench.TestMessage)
}
})
})
})
}
|