diff options
author | Martin Möhrmann <moehrmann@google.com> | 2020-10-20 09:56:14 +0200 |
---|---|---|
committer | Martin Möhrmann <moehrmann@google.com> | 2020-10-20 21:30:18 +0000 |
commit | b7a2d413a3f710f14accedf185c93bfb63d24fd0 (patch) | |
tree | 0b742d64de218eae529e71a0c7bbe56119b6bbdc /src/testing | |
parent | 80182d45b5d2ff86da7b6587a2a09d8924dd0a95 (diff) | |
download | go-b7a2d413a3f710f14accedf185c93bfb63d24fd0.tar.gz go-b7a2d413a3f710f14accedf185c93bfb63d24fd0.zip |
testing: print cpu type as label for benchmarks
Supports 386 and amd64 architectures on all operating systems.
Example output:
$ go test -bench=.*
goos: darwin
goarch: amd64
pkg: strconv
cpu: Intel(R) Core(TM) i7-3520M CPU @ 2.90GHz
BenchmarkAtof64Decimal-4 24431032 46.8 ns/op
...
As the displayed CPU information is only used for information
purposes it is lazily initialized when needed using the new
internal/sysinfo package.
This allows internal/cpu to stay without dependencies and avoid
initialization costs when the CPU information is not needed as
the new code to query the CPU name in internal/cpu can be
dead code eliminated if not used.
Fixes #39214
Change-Id: I77ae5c5d2fed6b28fa78dd45075f9f0a6a7f1bfd
Reviewed-on: https://go-review.googlesource.com/c/go/+/263804
Trust: Martin Möhrmann <moehrmann@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
Diffstat (limited to 'src/testing')
-rw-r--r-- | src/testing/benchmark.go | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/src/testing/benchmark.go b/src/testing/benchmark.go index e9687bf26d..1b81ec3a2d 100644 --- a/src/testing/benchmark.go +++ b/src/testing/benchmark.go @@ -8,6 +8,7 @@ import ( "flag" "fmt" "internal/race" + "internal/sysinfo" "io" "math" "os" @@ -262,6 +263,9 @@ func (b *B) run() { if b.importPath != "" { fmt.Fprintf(b.w, "pkg: %s\n", b.importPath) } + if cpu := sysinfo.CPU.Name(); cpu != "" { + fmt.Fprintf(b.w, "cpu: %s\n", cpu) + } }) if b.context != nil { // Running go test --test.bench @@ -648,6 +652,9 @@ func (b *B) Run(name string, f func(b *B)) bool { if b.importPath != "" { fmt.Printf("pkg: %s\n", b.importPath) } + if cpu := sysinfo.CPU.Name(); cpu != "" { + fmt.Printf("cpu: %s\n", cpu) + } }) fmt.Println(benchName) |