Debian Codegraph @

slog/benchmarks/zerolog_benchmarks/zerolog_benchmarks_test.go

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