Skip to content

Commit

Permalink
fix benchmark result value from go test -bench is float number (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
rhysd committed Jan 1, 2020
1 parent 673f297 commit 5951ab8
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,8 @@ function extractGoResult(output: string): BenchmarkResult[] {
const ret = [];
// Example:
// BenchmarkFib20-8 30000 41653 ns/op
const reExtract = /^(Benchmark\w+)(-\d+)?\s+(\d+)\s+(\d+)\s+(.+)$/;
// BenchmarkDoWithConfigurer1-8 30000000 42.3 ns/op
const reExtract = /^(Benchmark\w+)(-\d+)?\s+(\d+)\s+([0-9.]+)\s+(.+)$/;

for (const line of lines) {
const m = line.match(reExtract);
Expand All @@ -218,7 +219,7 @@ function extractGoResult(output: string): BenchmarkResult[] {
const name = m[1];
const procs = m[2] !== undefined ? m[2].slice(1) : null;
const times = m[3];
const value = parseInt(m[4], 10);
const value = parseFloat(m[4]);
const unit = m[5];

let extra = `${times} times`;
Expand Down
2 changes: 1 addition & 1 deletion test/data/extract/go_output.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
goos: darwin
goarch: amd64
BenchmarkFib10-8 5000000 325 ns/op
BenchmarkFib20 30000 40537 ns/op
BenchmarkFib20 30000 40537.123 ns/op
PASS
ok _/Users/rhayasd/Develop/github.com/rhysd/github-action-benchmark/examples/go 3.614s
2 changes: 1 addition & 1 deletion test/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ describe('extractResult()', function() {
{
name: 'BenchmarkFib20',
unit: 'ns/op',
value: 40537,
value: 40537.123,
extra: '30000 times',
},
],
Expand Down

0 comments on commit 5951ab8

Please sign in to comment.