From 9a1666d75c87cf70dd24113f4384824eb96e4ccf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=ABl=20Stemmer?= Date: Sun, 12 Jun 2022 22:54:12 +0100 Subject: [PATCH] gtr,junit: Move Benchmark duration calculation to gtr package --- gtr/gtr.go | 6 ++++++ junit/junit.go | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/gtr/gtr.go b/gtr/gtr.go index b410c98..5fb23fa 100644 --- a/gtr/gtr.go +++ b/gtr/gtr.go @@ -103,6 +103,12 @@ type Benchmark struct { 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. type Error struct { ID int diff --git a/junit/junit.go b/junit/junit.go index 816645c..1b90188 100644 --- a/junit/junit.go +++ b/junit/junit.go @@ -235,7 +235,7 @@ func createTestcaseForBenchmark(pkgName string, bm gtr.Benchmark) Testcase { tc := Testcase{ Classname: pkgName, Name: bm.Name, - Time: formatBenchmarkTime(time.Duration(bm.NsPerOp) * time.Duration(bm.Iterations)), + Time: formatBenchmarkTime(bm.ApproximateDuration()), } if bm.Result == gtr.Fail {