From ac6afd77dc4b047b1f403fdd4e02f76a24a566c6 Mon Sep 17 00:00:00 2001 From: Joe Kimmel Date: Tue, 19 Apr 2022 11:33:57 -0700 Subject: [PATCH] use more recent version of go allows go benchmarks to work with extra metrics --- .github/workflows/ci.yml | 4 +++- .github/workflows/go.yml | 2 ++ examples/go/fib_test.go | 2 ++ src/extract.ts | 25 +++++++++++++++++-------- test/data/extract/go_output.txt | 3 +++ test/extract.spec.ts | 24 ++++++++++++++++++++++++ 6 files changed, 51 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1b036d140..5374502ef 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -45,6 +45,8 @@ jobs: - uses: actions/checkout@v2 - uses: actions/setup-node@v1 - uses: actions/setup-go@v1 + with: + go-version: "1.17.6" - uses: actions/cache@v1 with: path: ~/.npm @@ -58,7 +60,7 @@ jobs: cp ./dev/bench/data.js before_data.js git checkout - - name: Run benchmark - run: cd examples/go && go test -bench 'BenchmarkFib' | tee output.txt + run: cd examples/go && go test ./fib_test.go ./fib.go -bench 'BenchmarkFib' | tee output.txt - name: Store benchmark result uses: ./ with: diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 6f3548699..171e8f013 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -15,6 +15,8 @@ jobs: steps: - uses: actions/checkout@v2 - uses: actions/setup-go@v1 + with: + go-version: "1.17.6" - name: Run benchmark run: cd examples/go && go test -bench 'BenchmarkFib' | tee output.txt - name: Store benchmark result diff --git a/examples/go/fib_test.go b/examples/go/fib_test.go index 51c3777f2..daf19454f 100644 --- a/examples/go/fib_test.go +++ b/examples/go/fib_test.go @@ -8,10 +8,12 @@ func BenchmarkFib10(b *testing.B) { for i := 0; i < b.N; i++ { var _ = Fib(10) } + b.ReportMetric(3.0, "auxMetricUnits") } func BenchmarkFib20(b *testing.B) { for i := 0; i < b.N; i++ { var _ = Fib(20) } + b.ReportMetric(4.0, "auxMetricUnits") } diff --git a/src/extract.ts b/src/extract.ts index e9ed1c124..dbca71a97 100644 --- a/src/extract.ts +++ b/src/extract.ts @@ -306,7 +306,13 @@ function extractGoResult(output: string): BenchmarkResult[] { // Example: // BenchmarkFib20-8 30000 41653 ns/op // BenchmarkDoWithConfigurer1-8 30000000 42.3 ns/op - const reExtract = /^(Benchmark\w+(?:\/?[\w()$%^&*-]*?)*?)(-\d+)?\s+(\d+)\s+([0-9.]+)\s+(.+)$/; + // Example if someone has used the ReportMetric function to add additional metrics to each benchmark: + // BenchmarkThing-16 1 95258906556 ns/op 64.02 UnitsForMeasure2 31.13 UnitsForMeasure3 + + // reference, "Proposal: Go Benchmark Data Format": https://go.googlesource.com/proposal/+/master/design/14313-benchmark-format.md + // "A benchmark result line has the general form: [ ...]" + // "The fields are separated by runs of space characters (as defined by unicode.IsSpace), so the line can be parsed with strings.Fields. The line must have an even number of fields, and at least four." + const reExtract = /^(Benchmark\w+(?:\/?[\w()$%^&*-]*?)*?)(-\d+)?\s+(\d+)\s+(.+)$/; for (const line of lines) { const m = line.match(reExtract); @@ -317,15 +323,18 @@ 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 = parseFloat(m[4]); - const unit = m[5]; + const remainder = m[4]; - let extra = `${times} times`; - if (procs !== null) { - extra += `\n${procs} procs`; + const pieces = remainder.split(/[ \t]+/); + for (let i = 0; i < pieces.length; i = i + 2) { + let extra = `${times} times`.replace(/\s\s+/g, ' '); + if (procs !== null) { + extra += `\n${procs} procs`; + } + const value = parseFloat(pieces[i]); + const unit = pieces[i + 1]; + ret.push({ name, value, unit, extra }); } - - ret.push({ name, value, unit, extra }); } return ret; diff --git a/test/data/extract/go_output.txt b/test/data/extract/go_output.txt index 6472966f9..66ca5336f 100644 --- a/test/data/extract/go_output.txt +++ b/test/data/extract/go_output.txt @@ -5,5 +5,8 @@ BenchmarkFib20 30000 40537.123 ns/op BenchmarkFib/my_tabled_benchmark_-_10-8 5000000 325 ns/op BenchmarkFib/my_tabled_benchmark_-_20 30000 40537.123 ns/op BenchmarkFib/my/tabled/benchmark_-_20 30001 40537.456 ns/op +BenchmarkFib11-16 4587789 262.7 ns/op 3.000 auxMetricUnits +BenchmarkFib22-16 37653 31915 ns/op 4.000 auxMetricUnits +PASS PASS ok _/Users/rhayasd/Develop/github.com/benchmark-action/github-action-benchmark/examples/go 3.614s diff --git a/test/extract.spec.ts b/test/extract.spec.ts index 80f79e6a8..40a6a8c3f 100644 --- a/test/extract.spec.ts +++ b/test/extract.spec.ts @@ -199,6 +199,30 @@ describe('extractResult()', function () { value: 40537.456, extra: '30001 times', }, + { + name: 'BenchmarkFib11', + unit: 'ns/op', + value: 262.7, + extra: '4587789 times\n16 procs', + }, + { + name: 'BenchmarkFib11', + unit: 'auxMetricUnits', + value: 3, + extra: '4587789 times\n16 procs', + }, + { + name: 'BenchmarkFib22', + unit: 'ns/op', + value: 31915, + extra: '37653 times\n16 procs', + }, + { + name: 'BenchmarkFib22', + unit: 'auxMetricUnits', + value: 4, + extra: '37653 times\n16 procs', + }, ], }, {