gtr: Improve accuracy of benchmark duration calculation

The NsPerOp was previously casted to a time.Duration (int64) before
multiplying it with the number of iterations. This has been fixed by
doing the casting after the multiplication. The resulting duration
should be a bit more accurate.
This commit is contained in:
Joël Stemmer 2022-06-12 22:56:04 +01:00
parent 9a1666d75c
commit 1d905e0b1c
7 changed files with 13 additions and 13 deletions

View File

@ -106,7 +106,7 @@ type Benchmark struct {
// ApproximateDuration returns the duration calculated by multiplying the
// iterations and average time per iteration (NsPerOp).
func (b Benchmark) ApproximateDuration() time.Duration {
return time.Duration(b.NsPerOp) * time.Duration(b.Iterations)
return time.Duration(float64(b.Iterations)*b.NsPerOp) * time.Nanosecond
}
// Error contains details of a build or runtime error.

View File

@ -7,7 +7,7 @@
<testcase name="TestOne" classname="package/bench" time="0.000">
<system-out><![CDATA[ bench_test.go:9: test log]]></system-out>
</testcase>
<testcase name="BenchmarkOne" classname="package/bench" time="0.000000000">
<testcase name="BenchmarkOne" classname="package/bench" time="0.264200000">
<system-out><![CDATA[ bench_test.go:13: benchmark log (1)
bench_test.go:13: benchmark log (100)
bench_test.go:13: benchmark log (10000)
@ -15,7 +15,7 @@
bench_test.go:13: benchmark log (100000000)
bench_test.go:13: benchmark log (1000000000)]]></system-out>
</testcase>
<testcase name="BenchmarkTwo" classname="package/bench" time="1.305496599"></testcase>
<testcase name="BenchmarkTwo" classname="package/bench" time="1.313804304"></testcase>
<system-out><![CDATA[goos: linux
goarch: amd64
pkg: package/bench]]></system-out>

View File

@ -4,8 +4,8 @@
<properties>
<property name="go.version" value="1.0"></property>
</properties>
<testcase name="BenchmarkOne" classname="package/bench" time="0.000000000"></testcase>
<testcase name="BenchmarkTwo" classname="package/bench" time="1.312990536"></testcase>
<testcase name="BenchmarkOne" classname="package/bench" time="0.264000000"></testcase>
<testcase name="BenchmarkTwo" classname="package/bench" time="1.316969295"></testcase>
<system-out><![CDATA[goos: linux
goarch: amd64
pkg: package/bench

View File

@ -4,7 +4,7 @@
<properties>
<property name="go.version" value="1.0"></property>
</properties>
<testcase name="BenchmarkNew" classname="pkg/count" time="8.800000000"></testcase>
<testcase name="BenchmarkFew" classname="pkg/count" time="2.550000000"></testcase>
<testcase name="BenchmarkNew" classname="pkg/count" time="8.820000000"></testcase>
<testcase name="BenchmarkFew" classname="pkg/count" time="2.555000000"></testcase>
</testsuite>
</testsuites>

View File

@ -4,9 +4,9 @@
<properties>
<property name="go.version" value="1.0"></property>
</properties>
<testcase name="BenchmarkItsy" classname="really/small" time="1.350000000"></testcase>
<testcase name="BenchmarkTeeny" classname="really/small" time="2.000000000"></testcase>
<testcase name="BenchmarkWeeny" classname="really/small" time="0.000000000"></testcase>
<testcase name="BenchmarkItsy" classname="really/small" time="1.371000000"></testcase>
<testcase name="BenchmarkTeeny" classname="really/small" time="2.120000000"></testcase>
<testcase name="BenchmarkWeeny" classname="really/small" time="0.520000000"></testcase>
<system-out><![CDATA[goos: darwin
goarch: amd64
pkg: really/small]]></system-out>

View File

@ -4,7 +4,7 @@
<properties>
<property name="go.version" value="1.0"></property>
</properties>
<testcase name="BenchmarkRing" classname="single/cpu" time="1.480000000"></testcase>
<testcase name="BenchmarkRing" classname="single/cpu" time="1.484000000"></testcase>
<system-out><![CDATA[pkg: single/cpu]]></system-out>
</testsuite>
</testsuites>

View File

@ -10,7 +10,7 @@
<testcase name="TestZ" classname="package/name/bench" time="0.000">
<system-out><![CDATA[ z_test.go:6: ok]]></system-out>
</testcase>
<testcase name="BenchmarkTest" classname="package/name/bench" time="0.000000000">
<testcase name="BenchmarkTest" classname="package/name/bench" time="0.440700000">
<system-out><![CDATA[ bench_test.go:12: 1
bench_test.go:12: 100
bench_test.go:12: 10000
@ -18,7 +18,7 @@
bench_test.go:12: 100000000
bench_test.go:12: 1000000000]]></system-out>
</testcase>
<testcase name="BenchmarkOtherTest" classname="package/name/bench" time="0.000000000"></testcase>
<testcase name="BenchmarkOtherTest" classname="package/name/bench" time="0.263900000"></testcase>
<system-out><![CDATA[goos: linux
goarch: amd64
pkg: package/name/bench]]></system-out>