slog: benchmarks

Add benchmarks to measure the performance of LogAttrs and compare it
with Zap.

The run_benchmarks.sh script will run the benchmarks 5 times both with
and without the code to fetch the pc, and write the results to
files. That code is currently slow (200ns) so we optimistically
disable it.

Put the equivalent Zap benchmarks in a subdirectory, zapbenchmarks,
which is in a separate module to avoid having golang.org/x/exp depend
on go.uber.org/zap.  The Zap benchmarks are named identically to the
slog ones so benchstat can compare them. The
zapbenchmarks/run_benchmarks.sh script runs the benchmarks, puts the
output in a file, and rename the "pkg:" header in the file to match
the slog benchmarks package so that benchstat will compare them.

We test only the Logger.LogAttrs method. That is the intended fast
path of the package.  It might be interesting to see how much slower
the methods that take ...any are, but we don't do that in this CL.

We use io.Discard for all output, to keep extraneous effects to a
minimum.  But again, it would be interesting to compare that with
writing to a file, for instance.

Our original benchmarks defined a simple binary format and had
handlers that produced it. But the fact is, people don't seem to do
that, even people who want high performance. So again, interesting,
but not on the critical path.

These benchmarks show that slog is competitive with Zap even with
pc-fetching enabled, and significantly faster without it.

Change-Id: I88cf12f6e3b2a0eab894664cb106f3b4ec3996c4
Reviewed-on: https://go-review.googlesource.com/c/exp/+/436759
Run-TryBot: Jonathan Amsterdam <jba@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
17 files changed
tree: 614c421aa02580807e936e7b8c9ef959a8d13f7e
  1. apidiff/
  2. cmd/
  3. constraints/
  4. devtools/
  5. ebnf/
  6. ebnflint/
  7. errors/
  8. event/
  9. inotify/
  10. io/
  11. jsonrpc2/
  12. maps/
  13. mmap/
  14. rand/
  15. shiny/
  16. shootout/
  17. slices/
  18. slog/
  19. sumdb/
  20. typeparams/
  21. utf8string/
  22. .gitattributes
  23. .gitignore
  24. codereview.cfg
  25. CONTRIBUTING.md
  26. go.mod
  27. go.sum
  28. LICENSE
  29. PATENTS
  30. README.md
README.md

exp

PkgGoDev

This subrepository holds experimental and deprecated (in the old directory) packages.

The idea for this subrepository originated as the pkg/exp directory of the main repository, but its presence there made it unavailable to users of the binary downloads of the Go installation. The subrepository has therefore been created to make it possible to go get these packages.

Warning: Packages here are experimental and unreliable. Some may one day be promoted to the main repository or other subrepository, or they may be modified arbitrarily or even disappear altogether.

In short, code in this subrepository is not subject to the Go 1 compatibility promise. (No subrepo is, but the promise is even more likely to be violated by go.exp than the others.)

Caveat emptor.