Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
Signed-off-by: Ziwen Ning <[email protected]>
  • Loading branch information
ningziwen committed Jul 7, 2023
1 parent 464e613 commit 31e8e92
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 44 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/ci-results-repo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
10 changes: 6 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/commit-comment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/minimal.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion examples/go/fib_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
3 changes: 3 additions & 0 deletions examples/go/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/github-action-benchmark/github-action-benchmark/examples/go

go 1.20
35 changes: 17 additions & 18 deletions src/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: <name> <iterations> <value> <unit> [<value> <unit>...]"
// "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 =
/^(?<name>Benchmark\w+(?:\/?[\w()$%^&*-=,]*?)*?)(?<procs>-\d+)?\s+(?<times>\d+)\s+(?<remainder>.+)$/;

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 });
}
}

Expand Down
4 changes: 2 additions & 2 deletions test/data/extract/go_output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
22 changes: 11 additions & 11 deletions test/extract.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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);
});
}

Expand Down

0 comments on commit 31e8e92

Please sign in to comment.