Skip to content

Commit 1721192

Browse files
committed
slog/benchmarks: benchmark for disabled logging
Add a benchmark measuring logging when Handler.Enabled returns false. Also, update the stored benchmark results. Change-Id: If4c710c1f620880c02408f94ae59cd50fcf40c71 Reviewed-on: https://go-review.googlesource.com/c/exp/+/439057 Run-TryBot: Jonathan Amsterdam <jba@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Alan Donovan <adonovan@google.com>
1 parent b6b77ba commit 1721192

File tree

4 files changed

+166
-122
lines changed

4 files changed

+166
-122
lines changed

slog/benchmarks/benchmarks_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ func BenchmarkAttrs(b *testing.B) {
2020
name string
2121
h slog.Handler
2222
}{
23+
{"disabled", disabledHandler{}},
2324
{"async discard", newAsyncHandler()},
2425
{"fastText discard", newFastTextHandler(io.Discard)},
2526
{"Text discard", slog.NewTextHandler(io.Discard)},

slog/benchmarks/handlers.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,3 +131,16 @@ func (*asyncHandler) With([]slog.Attr) slog.Handler {
131131
func (*asyncHandler) WithScope(string) slog.Handler {
132132
panic("asyncHandler: WithScope unimplemented")
133133
}
134+
135+
type disabledHandler struct{}
136+
137+
func (disabledHandler) Enabled(slog.Level) bool { return false }
138+
func (disabledHandler) Handle(slog.Record) error { panic("should not be called") }
139+
140+
func (disabledHandler) With([]slog.Attr) slog.Handler {
141+
panic("disabledHandler: With unimplemented")
142+
}
143+
144+
func (disabledHandler) WithScope(string) slog.Handler {
145+
panic("disabledHandler: WithScope unimplemented")
146+
}

slog/benchmarks/slog-pc.bench

Lines changed: 76 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -2,65 +2,80 @@ goos: linux
22
goarch: amd64
33
pkg: golang.org/x/exp/slog/benchmarks
44
cpu: Intel(R) Xeon(R) CPU @ 2.20GHz
5-
BenchmarkAttrs/async_discard/5_args-8 3313623 358.6 ns/op 0 B/op 0 allocs/op
6-
BenchmarkAttrs/async_discard/5_args-8 3337614 363.7 ns/op 0 B/op 0 allocs/op
7-
BenchmarkAttrs/async_discard/5_args-8 3225496 359.6 ns/op 0 B/op 0 allocs/op
8-
BenchmarkAttrs/async_discard/5_args-8 3340921 357.4 ns/op 0 B/op 0 allocs/op
9-
BenchmarkAttrs/async_discard/5_args-8 3356816 357.9 ns/op 0 B/op 0 allocs/op
10-
BenchmarkAttrs/async_discard/10_args-8 1949758 623.7 ns/op 208 B/op 1 allocs/op
11-
BenchmarkAttrs/async_discard/10_args-8 1978635 615.7 ns/op 208 B/op 1 allocs/op
12-
BenchmarkAttrs/async_discard/10_args-8 1953513 623.0 ns/op 208 B/op 1 allocs/op
13-
BenchmarkAttrs/async_discard/10_args-8 1889458 642.6 ns/op 208 B/op 1 allocs/op
14-
BenchmarkAttrs/async_discard/10_args-8 1850548 639.3 ns/op 208 B/op 1 allocs/op
15-
BenchmarkAttrs/async_discard/40_args-8 592636 2039 ns/op 1408 B/op 1 allocs/op
16-
BenchmarkAttrs/async_discard/40_args-8 537145 2028 ns/op 1408 B/op 1 allocs/op
17-
BenchmarkAttrs/async_discard/40_args-8 576033 2001 ns/op 1408 B/op 1 allocs/op
18-
BenchmarkAttrs/async_discard/40_args-8 639178 2032 ns/op 1408 B/op 1 allocs/op
19-
BenchmarkAttrs/async_discard/40_args-8 499279 2030 ns/op 1408 B/op 1 allocs/op
20-
BenchmarkAttrs/fastText_discard/5_args-8 2776984 441.7 ns/op 0 B/op 0 allocs/op
21-
BenchmarkAttrs/fastText_discard/5_args-8 2745285 440.7 ns/op 0 B/op 0 allocs/op
22-
BenchmarkAttrs/fastText_discard/5_args-8 2749682 435.4 ns/op 0 B/op 0 allocs/op
23-
BenchmarkAttrs/fastText_discard/5_args-8 2725453 441.9 ns/op 0 B/op 0 allocs/op
24-
BenchmarkAttrs/fastText_discard/5_args-8 2733200 442.3 ns/op 0 B/op 0 allocs/op
25-
BenchmarkAttrs/fastText_discard/10_args-8 1382514 870.3 ns/op 208 B/op 1 allocs/op
26-
BenchmarkAttrs/fastText_discard/10_args-8 1381012 918.3 ns/op 208 B/op 1 allocs/op
27-
BenchmarkAttrs/fastText_discard/10_args-8 1387348 866.7 ns/op 208 B/op 1 allocs/op
28-
BenchmarkAttrs/fastText_discard/10_args-8 1394262 875.1 ns/op 208 B/op 1 allocs/op
29-
BenchmarkAttrs/fastText_discard/10_args-8 1376648 871.6 ns/op 208 B/op 1 allocs/op
30-
BenchmarkAttrs/fastText_discard/40_args-8 402344 3030 ns/op 1412 B/op 1 allocs/op
31-
BenchmarkAttrs/fastText_discard/40_args-8 378612 3008 ns/op 1412 B/op 1 allocs/op
32-
BenchmarkAttrs/fastText_discard/40_args-8 438976 3017 ns/op 1412 B/op 1 allocs/op
33-
BenchmarkAttrs/fastText_discard/40_args-8 406396 2995 ns/op 1412 B/op 1 allocs/op
34-
BenchmarkAttrs/fastText_discard/40_args-8 443701 3122 ns/op 1412 B/op 1 allocs/op
35-
BenchmarkAttrs/Text_discard/5_args-8 1322332 928.3 ns/op 8 B/op 2 allocs/op
36-
BenchmarkAttrs/Text_discard/5_args-8 1352413 933.9 ns/op 8 B/op 2 allocs/op
37-
BenchmarkAttrs/Text_discard/5_args-8 1274869 906.0 ns/op 8 B/op 2 allocs/op
38-
BenchmarkAttrs/Text_discard/5_args-8 1313193 909.8 ns/op 8 B/op 2 allocs/op
39-
BenchmarkAttrs/Text_discard/5_args-8 1358574 883.2 ns/op 8 B/op 2 allocs/op
40-
BenchmarkAttrs/Text_discard/10_args-8 847946 1489 ns/op 224 B/op 5 allocs/op
41-
BenchmarkAttrs/Text_discard/10_args-8 817272 1493 ns/op 224 B/op 5 allocs/op
42-
BenchmarkAttrs/Text_discard/10_args-8 800985 1471 ns/op 224 B/op 5 allocs/op
43-
BenchmarkAttrs/Text_discard/10_args-8 786033 1480 ns/op 224 B/op 5 allocs/op
44-
BenchmarkAttrs/Text_discard/10_args-8 950853 1494 ns/op 224 B/op 5 allocs/op
45-
BenchmarkAttrs/Text_discard/40_args-8 257581 4866 ns/op 1477 B/op 17 allocs/op
46-
BenchmarkAttrs/Text_discard/40_args-8 257049 4717 ns/op 1477 B/op 17 allocs/op
47-
BenchmarkAttrs/Text_discard/40_args-8 265626 4646 ns/op 1477 B/op 17 allocs/op
48-
BenchmarkAttrs/Text_discard/40_args-8 268263 4682 ns/op 1477 B/op 17 allocs/op
49-
BenchmarkAttrs/Text_discard/40_args-8 259975 4684 ns/op 1477 B/op 17 allocs/op
50-
BenchmarkAttrs/JSON_discard/5_args-8 1302524 965.7 ns/op 104 B/op 3 allocs/op
51-
BenchmarkAttrs/JSON_discard/5_args-8 1294948 927.6 ns/op 104 B/op 3 allocs/op
52-
BenchmarkAttrs/JSON_discard/5_args-8 1302220 936.2 ns/op 104 B/op 3 allocs/op
53-
BenchmarkAttrs/JSON_discard/5_args-8 1288591 912.6 ns/op 104 B/op 3 allocs/op
54-
BenchmarkAttrs/JSON_discard/5_args-8 1293116 956.7 ns/op 104 B/op 3 allocs/op
55-
BenchmarkAttrs/JSON_discard/10_args-8 810056 1559 ns/op 368 B/op 6 allocs/op
56-
BenchmarkAttrs/JSON_discard/10_args-8 800988 1570 ns/op 368 B/op 6 allocs/op
57-
BenchmarkAttrs/JSON_discard/10_args-8 774804 1551 ns/op 368 B/op 6 allocs/op
58-
BenchmarkAttrs/JSON_discard/10_args-8 789522 1589 ns/op 368 B/op 6 allocs/op
59-
BenchmarkAttrs/JSON_discard/10_args-8 730042 1546 ns/op 368 B/op 6 allocs/op
60-
BenchmarkAttrs/JSON_discard/40_args-8 243769 5058 ns/op 1910 B/op 18 allocs/op
61-
BenchmarkAttrs/JSON_discard/40_args-8 242502 5151 ns/op 1910 B/op 18 allocs/op
62-
BenchmarkAttrs/JSON_discard/40_args-8 228924 5072 ns/op 1910 B/op 18 allocs/op
63-
BenchmarkAttrs/JSON_discard/40_args-8 247141 5088 ns/op 1910 B/op 18 allocs/op
64-
BenchmarkAttrs/JSON_discard/40_args-8 244929 5097 ns/op 1910 B/op 18 allocs/op
5+
BenchmarkAttrs/disabled/5_args-8 100000000 10.02 ns/op 0 B/op 0 allocs/op
6+
BenchmarkAttrs/disabled/5_args-8 120896504 9.981 ns/op 0 B/op 0 allocs/op
7+
BenchmarkAttrs/disabled/5_args-8 100000000 10.23 ns/op 0 B/op 0 allocs/op
8+
BenchmarkAttrs/disabled/5_args-8 100000000 10.06 ns/op 0 B/op 0 allocs/op
9+
BenchmarkAttrs/disabled/5_args-8 120556380 9.942 ns/op 0 B/op 0 allocs/op
10+
BenchmarkAttrs/disabled/10_args-8 62952199 17.94 ns/op 0 B/op 0 allocs/op
11+
BenchmarkAttrs/disabled/10_args-8 63987754 18.04 ns/op 0 B/op 0 allocs/op
12+
BenchmarkAttrs/disabled/10_args-8 62148806 18.09 ns/op 0 B/op 0 allocs/op
13+
BenchmarkAttrs/disabled/10_args-8 60456765 18.01 ns/op 0 B/op 0 allocs/op
14+
BenchmarkAttrs/disabled/10_args-8 63532894 18.07 ns/op 0 B/op 0 allocs/op
15+
BenchmarkAttrs/disabled/40_args-8 18832660 63.05 ns/op 0 B/op 0 allocs/op
16+
BenchmarkAttrs/disabled/40_args-8 18503997 63.05 ns/op 0 B/op 0 allocs/op
17+
BenchmarkAttrs/disabled/40_args-8 18793000 63.33 ns/op 0 B/op 0 allocs/op
18+
BenchmarkAttrs/disabled/40_args-8 18851764 62.90 ns/op 0 B/op 0 allocs/op
19+
BenchmarkAttrs/disabled/40_args-8 18620378 63.33 ns/op 0 B/op 0 allocs/op
20+
BenchmarkAttrs/async_discard/5_args-8 3081579 386.9 ns/op 0 B/op 0 allocs/op
21+
BenchmarkAttrs/async_discard/5_args-8 2594556 389.4 ns/op 0 B/op 0 allocs/op
22+
BenchmarkAttrs/async_discard/5_args-8 3092631 387.6 ns/op 0 B/op 0 allocs/op
23+
BenchmarkAttrs/async_discard/5_args-8 3095012 396.3 ns/op 0 B/op 0 allocs/op
24+
BenchmarkAttrs/async_discard/5_args-8 3090172 389.4 ns/op 0 B/op 0 allocs/op
25+
BenchmarkAttrs/async_discard/10_args-8 1816550 682.2 ns/op 208 B/op 1 allocs/op
26+
BenchmarkAttrs/async_discard/10_args-8 1721044 692.5 ns/op 208 B/op 1 allocs/op
27+
BenchmarkAttrs/async_discard/10_args-8 1749418 674.9 ns/op 208 B/op 1 allocs/op
28+
BenchmarkAttrs/async_discard/10_args-8 1728466 712.4 ns/op 208 B/op 1 allocs/op
29+
BenchmarkAttrs/async_discard/10_args-8 1780058 676.4 ns/op 208 B/op 1 allocs/op
30+
BenchmarkAttrs/async_discard/40_args-8 510950 2316 ns/op 1408 B/op 1 allocs/op
31+
BenchmarkAttrs/async_discard/40_args-8 489726 2332 ns/op 1408 B/op 1 allocs/op
32+
BenchmarkAttrs/async_discard/40_args-8 464305 2298 ns/op 1408 B/op 1 allocs/op
33+
BenchmarkAttrs/async_discard/40_args-8 499432 2455 ns/op 1408 B/op 1 allocs/op
34+
BenchmarkAttrs/async_discard/40_args-8 462938 2300 ns/op 1408 B/op 1 allocs/op
35+
BenchmarkAttrs/fastText_discard/5_args-8 2519834 481.5 ns/op 0 B/op 0 allocs/op
36+
BenchmarkAttrs/fastText_discard/5_args-8 2521468 481.4 ns/op 0 B/op 0 allocs/op
37+
BenchmarkAttrs/fastText_discard/5_args-8 2465902 486.9 ns/op 0 B/op 0 allocs/op
38+
BenchmarkAttrs/fastText_discard/5_args-8 2511697 474.6 ns/op 0 B/op 0 allocs/op
39+
BenchmarkAttrs/fastText_discard/5_args-8 2455657 497.1 ns/op 0 B/op 0 allocs/op
40+
BenchmarkAttrs/fastText_discard/10_args-8 1217221 922.8 ns/op 208 B/op 1 allocs/op
41+
BenchmarkAttrs/fastText_discard/10_args-8 1303630 920.9 ns/op 208 B/op 1 allocs/op
42+
BenchmarkAttrs/fastText_discard/10_args-8 1331846 915.3 ns/op 208 B/op 1 allocs/op
43+
BenchmarkAttrs/fastText_discard/10_args-8 1300803 905.6 ns/op 208 B/op 1 allocs/op
44+
BenchmarkAttrs/fastText_discard/10_args-8 1342477 908.3 ns/op 208 B/op 1 allocs/op
45+
BenchmarkAttrs/fastText_discard/40_args-8 370690 3211 ns/op 1412 B/op 1 allocs/op
46+
BenchmarkAttrs/fastText_discard/40_args-8 382737 3269 ns/op 1413 B/op 1 allocs/op
47+
BenchmarkAttrs/fastText_discard/40_args-8 397886 3160 ns/op 1412 B/op 1 allocs/op
48+
BenchmarkAttrs/fastText_discard/40_args-8 389143 3125 ns/op 1412 B/op 1 allocs/op
49+
BenchmarkAttrs/fastText_discard/40_args-8 395041 3141 ns/op 1412 B/op 1 allocs/op
50+
BenchmarkAttrs/Text_discard/5_args-8 1205694 985.4 ns/op 8 B/op 2 allocs/op
51+
BenchmarkAttrs/Text_discard/5_args-8 1000000 1013 ns/op 8 B/op 2 allocs/op
52+
BenchmarkAttrs/Text_discard/5_args-8 1214325 977.5 ns/op 8 B/op 2 allocs/op
53+
BenchmarkAttrs/Text_discard/5_args-8 1202088 985.5 ns/op 8 B/op 2 allocs/op
54+
BenchmarkAttrs/Text_discard/5_args-8 1000000 1017 ns/op 8 B/op 2 allocs/op
55+
BenchmarkAttrs/Text_discard/10_args-8 771573 1641 ns/op 224 B/op 5 allocs/op
56+
BenchmarkAttrs/Text_discard/10_args-8 805484 1651 ns/op 224 B/op 5 allocs/op
57+
BenchmarkAttrs/Text_discard/10_args-8 756583 1652 ns/op 224 B/op 5 allocs/op
58+
BenchmarkAttrs/Text_discard/10_args-8 811674 1642 ns/op 224 B/op 5 allocs/op
59+
BenchmarkAttrs/Text_discard/10_args-8 812188 1630 ns/op 224 B/op 5 allocs/op
60+
BenchmarkAttrs/Text_discard/40_args-8 223544 5286 ns/op 1477 B/op 17 allocs/op
61+
BenchmarkAttrs/Text_discard/40_args-8 243157 5573 ns/op 1477 B/op 17 allocs/op
62+
BenchmarkAttrs/Text_discard/40_args-8 226200 5568 ns/op 1477 B/op 17 allocs/op
63+
BenchmarkAttrs/Text_discard/40_args-8 231757 5341 ns/op 1477 B/op 17 allocs/op
64+
BenchmarkAttrs/Text_discard/40_args-8 230116 5308 ns/op 1477 B/op 17 allocs/op
65+
BenchmarkAttrs/JSON_discard/5_args-8 1347787 893.8 ns/op 0 B/op 0 allocs/op
66+
BenchmarkAttrs/JSON_discard/5_args-8 1340078 880.7 ns/op 0 B/op 0 allocs/op
67+
BenchmarkAttrs/JSON_discard/5_args-8 1333688 899.6 ns/op 0 B/op 0 allocs/op
68+
BenchmarkAttrs/JSON_discard/5_args-8 1440332 825.5 ns/op 0 B/op 0 allocs/op
69+
BenchmarkAttrs/JSON_discard/5_args-8 1390076 851.6 ns/op 0 B/op 0 allocs/op
70+
BenchmarkAttrs/JSON_discard/10_args-8 865652 1498 ns/op 208 B/op 1 allocs/op
71+
BenchmarkAttrs/JSON_discard/10_args-8 857676 1501 ns/op 208 B/op 1 allocs/op
72+
BenchmarkAttrs/JSON_discard/10_args-8 895814 1483 ns/op 208 B/op 1 allocs/op
73+
BenchmarkAttrs/JSON_discard/10_args-8 943058 1497 ns/op 208 B/op 1 allocs/op
74+
BenchmarkAttrs/JSON_discard/10_args-8 888254 1452 ns/op 208 B/op 1 allocs/op
75+
BenchmarkAttrs/JSON_discard/40_args-8 232080 5004 ns/op 1412 B/op 1 allocs/op
76+
BenchmarkAttrs/JSON_discard/40_args-8 262764 4974 ns/op 1412 B/op 1 allocs/op
77+
BenchmarkAttrs/JSON_discard/40_args-8 249297 4970 ns/op 1412 B/op 1 allocs/op
78+
BenchmarkAttrs/JSON_discard/40_args-8 230474 4990 ns/op 1412 B/op 1 allocs/op
79+
BenchmarkAttrs/JSON_discard/40_args-8 248367 4970 ns/op 1412 B/op 1 allocs/op
6580
PASS
66-
ok golang.org/x/exp/slog/benchmarks 96.016s
81+
ok golang.org/x/exp/slog/benchmarks 113.516s

0 commit comments

Comments
 (0)