diff --git a/pkg/gtr/event.go b/pkg/gtr/event.go index 7f9cae9..afa15fb 100644 --- a/pkg/gtr/event.go +++ b/pkg/gtr/event.go @@ -46,7 +46,7 @@ type Event struct { // Benchmarks Iterations int64 - NsPerOp int64 + NsPerOp float64 BytesPerOp int64 AllocsPerOp int64 } diff --git a/pkg/parser/gotest/gotest.go b/pkg/parser/gotest/gotest.go index 9fd0961..e15af6d 100644 --- a/pkg/parser/gotest/gotest.go +++ b/pkg/parser/gotest/gotest.go @@ -100,7 +100,7 @@ func (p *parser) summary(result, name, duration, data, covpct, packages string) Name: name, Duration: parseSeconds(duration), Data: data, - CovPct: parseCoverage(covpct), + CovPct: parseFloat(covpct), CovPackages: parsePackages(packages), }) } @@ -108,7 +108,7 @@ func (p *parser) summary(result, name, duration, data, covpct, packages string) func (p *parser) coverage(percent, packages string) { p.add(gtr.Event{ Type: "coverage", - CovPct: parseCoverage(percent), + CovPct: parseFloat(percent), CovPackages: parsePackages(packages), }) } @@ -118,7 +118,7 @@ func (p *parser) benchmark(name, iterations, timePerOp, bytesPerOp, allocsPerOp Type: "benchmark", Name: name, Iterations: parseInt(iterations), - NsPerOp: parseInt(timePerOp), + NsPerOp: parseFloat(timePerOp), BytesPerOp: parseInt(bytesPerOp), AllocsPerOp: parseInt(allocsPerOp), }) @@ -137,12 +137,12 @@ func parseSeconds(s string) time.Duration { return d } -func parseCoverage(percent string) float64 { - if percent == "" { +func parseFloat(s string) float64 { + if s == "" { return 0 } // ignore error - pct, _ := strconv.ParseFloat(percent, 64) + pct, _ := strconv.ParseFloat(s, 64) return pct } diff --git a/pkg/parser/gotest/gotest_test.go b/pkg/parser/gotest/gotest_test.go index b3b1494..77e2d1b 100644 --- a/pkg/parser/gotest/gotest_test.go +++ b/pkg/parser/gotest/gotest_test.go @@ -400,7 +400,17 @@ var tests = []struct { {Type: "status", Result: "PASS"}, {Type: "summary", Result: "ok", Name: "mycode/benchmarks/channels", Duration: 47084 * time.Millisecond}, }}, - {"27-benchdecimal", []gtr.Event{}}, + {"27-benchdecimal", + []gtr.Event{ + {Type: "output", Data: "goos: darwin"}, + {Type: "output", Data: "goarch: amd64"}, + {Type: "output", Data: "pkg: really/small"}, + {Type: "benchmark", Name: "BenchmarkItsy", Iterations: 30000000, NsPerOp: 45.7}, + {Type: "benchmark", Name: "BenchmarkTeeny", Iterations: 1000000000, NsPerOp: 2.12}, + {Type: "benchmark", Name: "BenchmarkWeeny", Iterations: 2000000000, NsPerOp: 0.26}, + {Type: "status", Result: "PASS"}, + {Type: "summary", Result: "ok", Name: "really/small", Duration: 4344 * time.Millisecond}, + }}, {"28-bench-1cpu", []gtr.Event{}}, {"29-bench-16cpu", []gtr.Event{}}, {"30-stdout", []gtr.Event{}},