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")