gtr,junit: Move Benchmark duration calculation to gtr package

This commit is contained in:
Joël Stemmer 2022-06-12 22:54:12 +01:00
parent cb055227b7
commit 9a1666d75c
2 changed files with 7 additions and 1 deletions

View File

@ -103,6 +103,12 @@ type Benchmark struct {
AllocsPerOp int64 AllocsPerOp int64
} }
// 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)
}
// Error contains details of a build or runtime error. // Error contains details of a build or runtime error.
type Error struct { type Error struct {
ID int ID int

View File

@ -235,7 +235,7 @@ func createTestcaseForBenchmark(pkgName string, bm gtr.Benchmark) Testcase {
tc := Testcase{ tc := Testcase{
Classname: pkgName, Classname: pkgName,
Name: bm.Name, Name: bm.Name,
Time: formatBenchmarkTime(time.Duration(bm.NsPerOp) * time.Duration(bm.Iterations)), Time: formatBenchmarkTime(bm.ApproximateDuration()),
} }
if bm.Result == gtr.Fail { if bm.Result == gtr.Fail {