slog/benchmarks/zerolog_benchmarks: add locking
Add a mutex around the io.Writer to more accurately compare zerolog
with slog.JSONHandler.
Also rename the zerolog benchmark to match slog's JSON benchmark so
benchstat compares them with each other.
Change-Id: I462a9797e51050db35e717e924b30908f2e804f3
Reviewed-on: https://go-review.googlesource.com/c/exp/+/463816
Reviewed-by: Alan Donovan <adonovan@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Jonathan Amsterdam <jba@google.com>
diff --git a/slog/benchmarks/zerolog_benchmarks/out.bench b/slog/benchmarks/zerolog_benchmarks/out.bench
index 811276c..5a17121 100644
--- a/slog/benchmarks/zerolog_benchmarks/out.bench
+++ b/slog/benchmarks/zerolog_benchmarks/out.bench
@@ -2,25 +2,25 @@
goarch: amd64
pkg: golang.org/x/exp/slog/benchmarks/zerolog_benchmarks
cpu: Intel(R) Xeon(R) CPU @ 2.20GHz
-BenchmarkAttrs/fastText_discard/5_args-8 6418659 189.5 ns/op 0 B/op 0 allocs/op
-BenchmarkAttrs/fastText_discard/5_args-8 6533284 195.6 ns/op 0 B/op 0 allocs/op
-BenchmarkAttrs/fastText_discard/5_args-8 5889310 198.2 ns/op 0 B/op 0 allocs/op
-BenchmarkAttrs/fastText_discard/5_args-8 6604699 186.4 ns/op 0 B/op 0 allocs/op
-BenchmarkAttrs/fastText_discard/5_args-8 6355650 179.5 ns/op 0 B/op 0 allocs/op
-BenchmarkAttrs/fastText_discard/5_args-8 6616807 179.7 ns/op 0 B/op 0 allocs/op
-BenchmarkAttrs/fastText_discard/5_args-8 6906835 183.2 ns/op 0 B/op 0 allocs/op
-BenchmarkAttrs/fastText_discard/5_args-8 6206449 184.8 ns/op 0 B/op 0 allocs/op
-BenchmarkAttrs/fastText_discard/5_args-8 6946840 180.9 ns/op 0 B/op 0 allocs/op
-BenchmarkAttrs/fastText_discard/5_args-8 6482282 193.4 ns/op 0 B/op 0 allocs/op
-BenchmarkAttrs/fastText_discard/10_args-8 4138516 282.4 ns/op 0 B/op 0 allocs/op
-BenchmarkAttrs/fastText_discard/10_args-8 4230062 278.9 ns/op 0 B/op 0 allocs/op
-BenchmarkAttrs/fastText_discard/10_args-8 4168550 287.3 ns/op 0 B/op 0 allocs/op
-BenchmarkAttrs/fastText_discard/10_args-8 4263456 278.1 ns/op 0 B/op 0 allocs/op
-BenchmarkAttrs/fastText_discard/10_args-8 4329322 280.8 ns/op 0 B/op 0 allocs/op
-BenchmarkAttrs/fastText_discard/10_args-8 4063077 288.9 ns/op 0 B/op 0 allocs/op
-BenchmarkAttrs/fastText_discard/10_args-8 4137674 293.2 ns/op 0 B/op 0 allocs/op
-BenchmarkAttrs/fastText_discard/10_args-8 4281580 285.3 ns/op 0 B/op 0 allocs/op
-BenchmarkAttrs/fastText_discard/10_args-8 4209427 300.3 ns/op 0 B/op 0 allocs/op
-BenchmarkAttrs/fastText_discard/10_args-8 4304002 282.7 ns/op 0 B/op 0 allocs/op
+BenchmarkAttrs/JSON_discard/5_args-8 4295836 257.6 ns/op 0 B/op 0 allocs/op
+BenchmarkAttrs/JSON_discard/5_args-8 4331781 268.5 ns/op 0 B/op 0 allocs/op
+BenchmarkAttrs/JSON_discard/5_args-8 4549810 259.8 ns/op 0 B/op 0 allocs/op
+BenchmarkAttrs/JSON_discard/5_args-8 4431434 253.1 ns/op 0 B/op 0 allocs/op
+BenchmarkAttrs/JSON_discard/5_args-8 4828357 257.4 ns/op 0 B/op 0 allocs/op
+BenchmarkAttrs/JSON_discard/5_args-8 4508712 254.9 ns/op 0 B/op 0 allocs/op
+BenchmarkAttrs/JSON_discard/5_args-8 4662748 271.1 ns/op 0 B/op 0 allocs/op
+BenchmarkAttrs/JSON_discard/5_args-8 4425884 257.9 ns/op 0 B/op 0 allocs/op
+BenchmarkAttrs/JSON_discard/5_args-8 4504692 262.4 ns/op 0 B/op 0 allocs/op
+BenchmarkAttrs/JSON_discard/5_args-8 4908181 256.9 ns/op 0 B/op 0 allocs/op
+BenchmarkAttrs/JSON_discard/10_args-8 3953874 295.4 ns/op 0 B/op 0 allocs/op
+BenchmarkAttrs/JSON_discard/10_args-8 4068267 291.0 ns/op 0 B/op 0 allocs/op
+BenchmarkAttrs/JSON_discard/10_args-8 3752751 314.8 ns/op 0 B/op 0 allocs/op
+BenchmarkAttrs/JSON_discard/10_args-8 4080250 305.8 ns/op 0 B/op 0 allocs/op
+BenchmarkAttrs/JSON_discard/10_args-8 4091317 294.0 ns/op 0 B/op 0 allocs/op
+BenchmarkAttrs/JSON_discard/10_args-8 3743437 296.4 ns/op 0 B/op 0 allocs/op
+BenchmarkAttrs/JSON_discard/10_args-8 4025077 295.4 ns/op 0 B/op 0 allocs/op
+BenchmarkAttrs/JSON_discard/10_args-8 3885260 299.9 ns/op 0 B/op 0 allocs/op
+BenchmarkAttrs/JSON_discard/10_args-8 3930517 303.2 ns/op 0 B/op 0 allocs/op
+BenchmarkAttrs/JSON_discard/10_args-8 4015480 315.6 ns/op 0 B/op 0 allocs/op
PASS
-ok golang.org/x/exp/slog/benchmarks/zerolog_benchmarks 29.079s
+ok golang.org/x/exp/slog/benchmarks/zerolog_benchmarks 29.551s
diff --git a/slog/benchmarks/zerolog_benchmarks/zerolog_benchmarks_test.go b/slog/benchmarks/zerolog_benchmarks/zerolog_benchmarks_test.go
index d2cc8b7..61d14bf 100644
--- a/slog/benchmarks/zerolog_benchmarks/zerolog_benchmarks_test.go
+++ b/slog/benchmarks/zerolog_benchmarks/zerolog_benchmarks_test.go
@@ -16,8 +16,8 @@
// benchmarks in the parent directory.
func BenchmarkAttrs(b *testing.B) {
- logger := zerolog.New(io.Discard).With().Timestamp().Logger()
- b.Run("fastText discard", func(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) {