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 5, 2023
1 parent 464e613 commit 9b25b77
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 42 deletions.
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: 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
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
14 changes: 0 additions & 14 deletions scripts/ci_validate_modification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,20 +170,6 @@ function validateBenchmarkResultMod<T>(diff: Diff<T>, expectedBenchName: string,
if (suite.tool !== added.tool) {
throw new Error(`Tool is different between ${JSON.stringify(suite)} and ${JSON.stringify(added)}`);
}

for (const addedBench of added.benches) {
for (const prevBench of suite.benches) {
if (prevBench.name === addedBench.name) {
if (prevBench.unit !== addedBench.unit) {
throw new Error(
`Unit is different between previous benchmark and newly added benchmark: ${JSON.stringify(
prevBench,
)} v.v. ${JSON.stringify(addedBench)}`,
);
}
}
}
}
}
}

Expand Down
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 name = m.groups.name;
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];
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
2 changes: 1 addition & 1 deletion test/extract.spec.ts
Original file line number Diff line number Diff line change
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 9b25b77

Please sign in to comment.