-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Before: ``` $ go test -bench='.' ./benchmark/ goos: linux goarch: amd64 pkg: github.com/go-logr/logr/benchmark cpu: Intel(R) Xeon(R) W-2135 CPU @ 3.70GHz BenchmarkInfoOneArg-6 483949 2420 ns/op BenchmarkInfoSeveralArgs-6 359826 3302 ns/op BenchmarkV0Info-6 352570 3399 ns/op BenchmarkV9Info-6 9096120 130.3 ns/op BenchmarkError-6 366549 3280 ns/op BenchmarkWithValues-6 9936550 120.1 ns/op BenchmarkWithName-6 22592770 53.38 ns/op ``` After: ``` $ go test -bench='.' ./benchmark/ goos: linux goarch: amd64 pkg: github.com/go-logr/logr/benchmark cpu: Intel(R) Xeon(R) W-2135 CPU @ 3.70GHz BenchmarkInfoOneArg-6 514122 2291 ns/op BenchmarkInfoSeveralArgs-6 380796 3153 ns/op BenchmarkV0Info-6 376472 3150 ns/op BenchmarkV9Info-6 15167118 79.13 ns/op BenchmarkError-6 358990 3336 ns/op BenchmarkWithValues-6 7674392 155.9 ns/op BenchmarkWithName-6 23391848 50.33 ns/op ``` Logs that actually write are dominated by the cost of preparing the message. Logs which do not write (e.g. `V(9)`) are much faster here (thog glog raw is much faster still). The main difference is the variadic slice setup. This is a candidate for Go to optimize - it now knows that the args are only used inside the conditional (`Enabled()`), and when that path is not executed, it can elide that work.
- Loading branch information
Showing
3 changed files
with
91 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters