junit: Use the standard duration formatting for benchmark durations

Benchmark durations were originally formatted with higher precision
because they contained just the NsPerOp field. Now that we're
approximating the total duration they are more accurate and don't need
as many decimals.
This commit is contained in:
Joël Stemmer 2022-06-12 23:02:01 +01:00
parent 1d905e0b1c
commit f1ad02b733
14 changed files with 31 additions and 37 deletions

View File

@ -235,7 +235,7 @@ func createTestcaseForBenchmark(pkgName string, bm gtr.Benchmark) Testcase {
tc := Testcase{
Classname: pkgName,
Name: bm.Name,
Time: formatBenchmarkTime(bm.ApproximateDuration()),
Time: formatDuration(bm.ApproximateDuration()),
}
if bm.Result == gtr.Fail {
@ -258,12 +258,6 @@ func formatDuration(d time.Duration) string {
return fmt.Sprintf("%.3f", d.Seconds())
}
// formatBenchmarkTime returns the JUnit string representation of the given
// benchmark time.
func formatBenchmarkTime(d time.Duration) string {
return fmt.Sprintf("%.9f", d.Seconds())
}
// formatOutput combines the lines from the given output into a single string.
func formatOutput(output []string, indent int) string {
return strings.Join(output, "\n")

View File

@ -36,7 +36,7 @@ func TestCreateFromReport(t *testing.T) {
Testcases: []Testcase{
{
Name: "BenchmarkFail",
Time: "0.000000000",
Time: "0.000",
Failure: &Result{Message: "Failed"},
},
},

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.264200000">
<testcase name="BenchmarkOne" classname="package/bench" time="0.264">
<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.313804304"></testcase>
<testcase name="BenchmarkTwo" classname="package/bench" time="1.314"></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="BenchmarkIpsHistoryInsert" classname="package/one" time="1.577040000"></testcase>
<testcase name="BenchmarkIpsHistoryLookup" classname="package/one" time="1.520800000"></testcase>
<testcase name="BenchmarkIpsHistoryInsert" classname="package/one" time="1.577"></testcase>
<testcase name="BenchmarkIpsHistoryLookup" classname="package/one" time="1.521"></testcase>
<system-out><![CDATA[goos: darwin
goarch: amd64
pkg: code.internal/state]]></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.264000000"></testcase>
<testcase name="BenchmarkTwo" classname="package/bench" time="1.316969295"></testcase>
<testcase name="BenchmarkOne" classname="package/bench" time="0.264"></testcase>
<testcase name="BenchmarkTwo" classname="package/bench" time="1.317"></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.820000000"></testcase>
<testcase name="BenchmarkFew" classname="pkg/count" time="2.555000000"></testcase>
<testcase name="BenchmarkNew" classname="pkg/count" time="8.820"></testcase>
<testcase name="BenchmarkFew" classname="pkg/count" time="2.555"></testcase>
</testsuite>
</testsuites>

View File

@ -4,18 +4,18 @@
<properties>
<property name="go.version" value="1.0"></property>
</properties>
<testcase name="BenchmarkParse" classname="mycode/common" time="1.591000000"></testcase>
<testcase name="BenchmarkNewTask" classname="mycode/common" time="1.173000000"></testcase>
<testcase name="BenchmarkParse" classname="mycode/common" time="1.591"></testcase>
<testcase name="BenchmarkNewTask" classname="mycode/common" time="1.173"></testcase>
<system-out><![CDATA[pkg: mycode/common]]></system-out>
</testsuite>
<testsuite name="mycode/benchmarks/channels" tests="4" failures="0" errors="0" id="1" hostname="hostname" time="47.084" timestamp="2022-01-01T00:00:00Z">
<properties>
<property name="go.version" value="1.0"></property>
</properties>
<testcase name="BenchmarkFanout/Channel/10" classname="mycode/benchmarks/channels" time="2.336500000"></testcase>
<testcase name="BenchmarkFanout/Channel/100" classname="mycode/benchmarks/channels" time="1.248250000"></testcase>
<testcase name="BenchmarkFanout/Channel/1000" classname="mycode/benchmarks/channels" time="1.956720000"></testcase>
<testcase name="BenchmarkFanout/Channel/10000" classname="mycode/benchmarks/channels" time="1.205100000"></testcase>
<testcase name="BenchmarkFanout/Channel/10" classname="mycode/benchmarks/channels" time="2.337"></testcase>
<testcase name="BenchmarkFanout/Channel/100" classname="mycode/benchmarks/channels" time="1.248"></testcase>
<testcase name="BenchmarkFanout/Channel/1000" classname="mycode/benchmarks/channels" time="1.957"></testcase>
<testcase name="BenchmarkFanout/Channel/10000" classname="mycode/benchmarks/channels" time="1.205"></testcase>
<system-out><![CDATA[pkg: mycode/benchmarks/channels]]></system-out>
</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.371000000"></testcase>
<testcase name="BenchmarkTeeny" classname="really/small" time="2.120000000"></testcase>
<testcase name="BenchmarkWeeny" classname="really/small" time="0.520000000"></testcase>
<testcase name="BenchmarkItsy" classname="really/small" time="1.371"></testcase>
<testcase name="BenchmarkTeeny" classname="really/small" time="2.120"></testcase>
<testcase name="BenchmarkWeeny" classname="really/small" time="0.520"></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.484000000"></testcase>
<testcase name="BenchmarkRing" classname="single/cpu" time="1.484"></testcase>
<system-out><![CDATA[pkg: single/cpu]]></system-out>
</testsuite>
</testsuites>

View File

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

View File

@ -4,8 +4,8 @@
<properties>
<property name="go.version" value="1.0"></property>
</properties>
<testcase name="BenchmarkDecode/Digits/Huffman/1e4" classname="compress/flate" time="1.044270000"></testcase>
<testcase name="BenchmarkEncode/Digits/Huffman/1e4" classname="compress/flate" time="1.416700000"></testcase>
<testcase name="BenchmarkDecode/Digits/Huffman/1e4" classname="compress/flate" time="1.044"></testcase>
<testcase name="BenchmarkEncode/Digits/Huffman/1e4" classname="compress/flate" time="1.417"></testcase>
<system-out><![CDATA[goos: linux
goarch: amd64
pkg: compress/flate]]></system-out>

View File

@ -4,13 +4,13 @@
<properties>
<property name="go.version" value="1.0"></property>
</properties>
<testcase name="BenchmarkError" classname="package/name/benchfail" time="0.000000000">
<testcase name="BenchmarkError" classname="package/name/benchfail" time="0.000">
<failure message="Failed"></failure>
</testcase>
<testcase name="BenchmarkFatal" classname="package/name/benchfail" time="0.000000000">
<testcase name="BenchmarkFatal" classname="package/name/benchfail" time="0.000">
<failure message="Failed"></failure>
</testcase>
<testcase name="BenchmarkSkip" classname="package/name/benchfail" time="0.000000000">
<testcase name="BenchmarkSkip" classname="package/name/benchfail" time="0.000">
<skipped message="Skipped"></skipped>
</testcase>
<testcase name="Failure" classname="package/name/benchfail" time="0.000">

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.440700000">
<testcase name="BenchmarkTest" classname="package/name/bench" time="0.441">
<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.263900000"></testcase>
<testcase name="BenchmarkOtherTest" classname="package/name/bench" time="0.264"></testcase>
<system-out><![CDATA[goos: linux
goarch: amd64
pkg: package/name/bench]]></system-out>

View File

@ -4,13 +4,13 @@
<properties>
<property name="go.version" value="1.0"></property>
</properties>
<testcase name="BenchmarkError" classname="package/name/benchfail" time="0.000000000">
<testcase name="BenchmarkError" classname="package/name/benchfail" time="0.000">
<failure message="Failed"></failure>
</testcase>
<testcase name="BenchmarkFatal" classname="package/name/benchfail" time="0.000000000">
<testcase name="BenchmarkFatal" classname="package/name/benchfail" time="0.000">
<failure message="Failed"></failure>
</testcase>
<testcase name="BenchmarkSkip" classname="package/name/benchfail" time="0.000000000">
<testcase name="BenchmarkSkip" classname="package/name/benchfail" time="0.000">
<skipped message="Skipped"></skipped>
</testcase>
<testcase name="Failure" classname="package/name/benchfail" time="0.000">