-
Notifications
You must be signed in to change notification settings - Fork 78
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 3013077 400.9 ns/op BenchmarkInfoSeveralArgs-6 1162088 1039 ns/op BenchmarkV0Info-6 754347 1418 ns/op BenchmarkV9Info-6 4605950 267.8 ns/op BenchmarkError-6 935028 1135 ns/op BenchmarkWithValues-6 5127631 232.5 ns/op BenchmarkWithName-6 12850569 106.5 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 2465788 475.7 ns/op BenchmarkInfoSeveralArgs-6 893026 1226 ns/op BenchmarkV0Info-6 817473 1250 ns/op BenchmarkV9Info-6 8595180 155.1 ns/op BenchmarkError-6 1000000 1371 ns/op BenchmarkWithValues-6 3902214 292.0 ns/op BenchmarkWithName-6 11271037 106.6 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 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