File: zerolog_benchmarks_test.go

package info (click to toggle)
golang-golang-x-exp 0.0~git20230522.2e198f4-1~bpo12%2B1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-backports
  • size: 6,404 kB
  • sloc: ansic: 1,900; objc: 276; sh: 272; asm: 48; makefile: 26
file content (55 lines) | stat: -rw-r--r-- 1,532 bytes parent folder | download | duplicates (3)
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)
				}
			})
		})
	})
}