From 31e8e92fa17ec67e80e2d5082ec16a29a8cc31b6 Mon Sep 17 00:00:00 2001 From: Ziwen Ning Date: Tue, 4 Jul 2023 13:50:08 -0700 Subject: [PATCH] address comments Signed-off-by: Ziwen Ning --- .github/workflows/ci-results-repo.yml | 8 ++++-- .github/workflows/ci.yml | 10 +++++--- .github/workflows/commit-comment.yml | 4 ++- .github/workflows/go.yml | 4 +-- .github/workflows/minimal.yml | 4 ++- README.md | 8 ++++-- examples/go/fib_test.go | 7 +++++- examples/go/go.mod | 3 +++ src/extract.ts | 35 +++++++++++++-------------- test/data/extract/go_output.txt | 4 +-- test/extract.spec.ts | 22 ++++++++--------- 11 files changed, 65 insertions(+), 44 deletions(-) create mode 100644 examples/go/go.mod diff --git a/.github/workflows/ci-results-repo.yml b/.github/workflows/ci-results-repo.yml index 7bd4d2b4f..34a88fd79 100644 --- a/.github/workflows/ci-results-repo.yml +++ b/.github/workflows/ci-results-repo.yml @@ -57,7 +57,9 @@ jobs: - uses: actions/setup-node@v3 with: node-version: 16 - - uses: actions/setup-go@v1 + - uses: actions/setup-go@v4 + with: + go-version: "stable" - uses: actions/cache@v1 with: path: ~/.npm @@ -336,7 +338,9 @@ jobs: key: ${{ runner.os }}-node-${{ hashFiles('package-lock.json') }} - run: npm ci - run: npm run build - - uses: actions/setup-go@v1 + - uses: actions/setup-go@v4 + with: + go-version: "stable" - name: Run benchmark run: cd examples/go && go test -bench 'BenchmarkFib' | tee output.txt - name: Download previous benchmark data diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ebcdedf1b..bdebb0728 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -49,9 +49,9 @@ jobs: - uses: actions/setup-node@v3 with: node-version: 16 - - uses: actions/setup-go@v1 + - uses: actions/setup-go@v4 with: - go-version: "1.17.6" + go-version: "stable" - uses: actions/cache@v1 with: path: ~/.npm @@ -65,7 +65,7 @@ jobs: cp ./dev/bench/data.js before_data.js git checkout - - name: Run benchmark - run: cd examples/go && go test ./fib_test.go ./fib.go -bench 'BenchmarkFib' | tee output.txt + run: cd examples/go && go test -bench 'BenchmarkFib' | tee output.txt - name: Store benchmark result uses: ./ with: @@ -348,7 +348,9 @@ jobs: key: ${{ runner.os }}-node-${{ hashFiles('package-lock.json') }} - run: npm ci - run: npm run build - - uses: actions/setup-go@v1 + - uses: actions/setup-go@v4 + with: + go-version: "stable" - name: Run benchmark run: cd examples/go && go test -bench 'BenchmarkFib' | tee output.txt - name: Download previous benchmark data diff --git a/.github/workflows/commit-comment.yml b/.github/workflows/commit-comment.yml index 8e35c12e1..be84cb948 100644 --- a/.github/workflows/commit-comment.yml +++ b/.github/workflows/commit-comment.yml @@ -14,7 +14,9 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - uses: actions/setup-go@v1 + - uses: actions/setup-go@v4 + with: + go-version: "stable" - name: Run benchmark run: cd examples/go && go test -bench 'BenchmarkFib' | tee output.txt - name: Download previous benchmark data diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 326285436..9c97db164 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -14,9 +14,9 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - uses: actions/setup-go@v1 + - uses: actions/setup-go@v4 with: - go-version: "1.17.6" + go-version: "stable" - name: Run benchmark run: cd examples/go && go test -bench 'BenchmarkFib' | tee output.txt diff --git a/.github/workflows/minimal.yml b/.github/workflows/minimal.yml index a17f35f79..d92abaa9f 100644 --- a/.github/workflows/minimal.yml +++ b/.github/workflows/minimal.yml @@ -14,7 +14,9 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - uses: actions/setup-go@v1 + - uses: actions/setup-go@v4 + with: + go-version: "stable" - name: Run benchmark run: cd examples/go && go test -bench 'BenchmarkFib' | tee output.txt - name: Download previous benchmark data diff --git a/README.md b/README.md index c4b6f2508..642efdb51 100644 --- a/README.md +++ b/README.md @@ -151,7 +151,9 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - uses: actions/setup-go@v1 + - uses: actions/setup-go@v4 + with: + go-version: "stable" # Run benchmark with `go test -bench` and stores the output to a file - name: Run benchmark run: go test -bench 'BenchmarkFib' | tee output.txt @@ -285,7 +287,9 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - uses: actions/setup-go@v1 + - uses: actions/setup-go@v4 + with: + go-version: "stable" # Run benchmark with `go test -bench` and stores the output to a file - name: Run benchmark run: go test -bench 'BenchmarkFib' | tee output.txt diff --git a/examples/go/fib_test.go b/examples/go/fib_test.go index daf19454f..5b92c203f 100644 --- a/examples/go/fib_test.go +++ b/examples/go/fib_test.go @@ -8,12 +8,17 @@ 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) } +} + +func BenchmarkFib20WithAuxMetric(b *testing.B) { + for i := 0; i < b.N; i++ { + var _ = Fib(20) + } b.ReportMetric(4.0, "auxMetricUnits") } diff --git a/examples/go/go.mod b/examples/go/go.mod new file mode 100644 index 000000000..b9be5c943 --- /dev/null +++ b/examples/go/go.mod @@ -0,0 +1,3 @@ +module github.com/github-action-benchmark/github-action-benchmark/examples/go + +go 1.20 diff --git a/src/extract.ts b/src/extract.ts index a99c83d4d..6219a2d77 100644 --- a/src/extract.ts +++ b/src/extract.ts @@ -352,28 +352,27 @@ function extractGoResult(output: string): BenchmarkResult[] { // 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+(.+)$/; + const reExtract = + /^(?Benchmark\w+(?:\/?[\w()$%^&*-=,]*?)*?)(?-\d+)?\s+(?\d+)\s+(?.+)$/; for (const line of lines) { const m = line.match(reExtract); - if (m === null) { - continue; - } - - const name = m[1]; - const procs = m[2] !== undefined ? m[2].slice(1) : null; - const times = m[3]; - const remainder = m[4]; - - 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`; + if (m?.groups) { + const procs = m.groups.procs !== undefined ? m.groups.procs.slice(1) : null; + const times = m.groups.times; + const remainder = m.groups.remainder; + + 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]; + const name = m.groups.name + ' - ' + unit; + ret.push({ name, value, unit, extra }); } - const value = parseFloat(pieces[i]); - const unit = pieces[i + 1]; - ret.push({ name, value, unit, extra }); } } diff --git a/test/data/extract/go_output.txt b/test/data/extract/go_output.txt index 966e03b4d..5b5d107cf 100644 --- a/test/data/extract/go_output.txt +++ b/test/data/extract/go_output.txt @@ -6,8 +6,8 @@ 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 BenchmarkFib/my/tabled/benchmark_-_20,var1=13,var2=14 30001 40537.456 ns/op -BenchmarkFib11-16 4587789 262.7 ns/op 3.000 auxMetricUnits -BenchmarkFib22-16 37653 31915 ns/op 4.000 auxMetricUnits +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 5c189b2c3..e87a53deb 100644 --- a/test/extract.spec.ts +++ b/test/extract.spec.ts @@ -174,61 +174,61 @@ describe('extractResult()', function () { tool: 'go', expected: [ { - name: 'BenchmarkFib10', + name: 'BenchmarkFib10 - ns/op', unit: 'ns/op', value: 325, extra: '5000000 times\n8 procs', }, { - name: 'BenchmarkFib20', + name: 'BenchmarkFib20 - ns/op', unit: 'ns/op', value: 40537.123, extra: '30000 times', }, { - name: 'BenchmarkFib/my_tabled_benchmark_-_10', + name: 'BenchmarkFib/my_tabled_benchmark_-_10 - ns/op', unit: 'ns/op', value: 325, extra: '5000000 times\n8 procs', }, { - name: 'BenchmarkFib/my_tabled_benchmark_-_20', + name: 'BenchmarkFib/my_tabled_benchmark_-_20 - ns/op', unit: 'ns/op', value: 40537.123, extra: '30000 times', }, { - name: 'BenchmarkFib/my/tabled/benchmark_-_20', + name: 'BenchmarkFib/my/tabled/benchmark_-_20 - ns/op', unit: 'ns/op', value: 40537.456, extra: '30001 times', }, { - name: 'BenchmarkFib/my/tabled/benchmark_-_20,var1=13,var2=14', + name: 'BenchmarkFib/my/tabled/benchmark_-_20,var1=13,var2=14 - ns/op', unit: 'ns/op', value: 40537.456, extra: '30001 times', }, { - name: 'BenchmarkFib11', + name: 'BenchmarkFib11 - ns/op', unit: 'ns/op', value: 262.7, extra: '4587789 times\n16 procs', }, { - name: 'BenchmarkFib11', + name: 'BenchmarkFib11 - auxMetricUnits', unit: 'auxMetricUnits', value: 3, extra: '4587789 times\n16 procs', }, { - name: 'BenchmarkFib22', + name: 'BenchmarkFib22 - ns/op', unit: 'ns/op', value: 31915, extra: '37653 times\n16 procs', }, { - name: 'BenchmarkFib22', + name: 'BenchmarkFib22 - auxMetricUnits', unit: 'auxMetricUnits', value: 4, extra: '37653 times\n16 procs', @@ -490,7 +490,7 @@ describe('extractResult()', function () { A.equal(bench.commit, dummyWebhookPayload.head_commit); A.ok(bench.date <= Date.now(), bench.date.toString()); A.equal(bench.tool, test.tool); - A.deepEqual(test.expected, bench.benches); + A.deepEqual(bench.benches, test.expected); }); }