Skip to content

Commit f6ab2e2

Browse files
ktrzblaine-arcjet
andauthored
fix: Support sub-nanosecond precision on Cargo benchmarks (#246)
* add test to cover new more precise format * change regexp and parsing of the number to cover sub-nanosecond precision --------- Co-authored-by: blaine-arcjet <[email protected]>
1 parent 8e74972 commit f6ab2e2

File tree

5 files changed

+50
-3
lines changed

5 files changed

+50
-3
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
## Unreleased
2+
- **fix** Support sub-nanosecond precision on Cargo benchmarks (#246)
3+
24

35
<a name="v1.20.1"></a>
46
# [v1.20.1](https://github.com/benchmark-action/github-action-benchmark/releases/tag/v1.20.1) - 02 Apr 2024

src/extract.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -314,8 +314,8 @@ function extractCargoResult(output: string): BenchmarkResult[] {
314314
const lines = output.split(/\r?\n/g);
315315
const ret = [];
316316
// Example:
317-
// test bench_fib_20 ... bench: 37,174 ns/iter (+/- 7,527)
318-
const reExtract = /^test (.+)\s+\.\.\. bench:\s+([0-9,]+) ns\/iter \(\+\/- ([0-9,]+)\)$/;
317+
// test bench_fib_20 ... bench: 37,174.25 ns/iter (+/- 7,527.43)
318+
const reExtract = /^test (.+)\s+\.\.\. bench:\s+([0-9,.]+) ns\/iter \(\+\/- ([0-9,.]+)\)$/;
319319
const reComma = /,/g;
320320

321321
for (const line of lines) {
@@ -325,7 +325,7 @@ function extractCargoResult(output: string): BenchmarkResult[] {
325325
}
326326

327327
const name = m[1].trim();
328-
const value = parseInt(m[2].replace(reComma, ''), 10);
328+
const value = parseFloat(m[2].replace(reComma, ''));
329329
const range = m[3].replace(reComma, '');
330330

331331
ret.push({

test/__snapshots__/extract.spec.ts.snap

+29
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,35 @@ exports[`extractResult() extracts benchmark output from cargo - cargo_output2.tx
175175
}
176176
`;
177177

178+
exports[`extractResult() extracts benchmark output from cargo - cargo_output3.txt 1`] = `
179+
{
180+
"benches": [
181+
{
182+
"name": "bench_fib_10",
183+
"range": "± 2.21",
184+
"unit": "ns/iter",
185+
"value": 148.7,
186+
},
187+
{
188+
"name": "bench_fib_20",
189+
"range": "± 440.25",
190+
"unit": "ns/iter",
191+
"value": 18794.12,
192+
},
193+
],
194+
"commit": {
195+
"author": null,
196+
"committer": null,
197+
"id": "123456789abcdef",
198+
"message": "this is dummy",
199+
"timestamp": "dummy timestamp",
200+
"url": "https://github.com/dummy/repo",
201+
},
202+
"date": 1712131503296,
203+
"tool": "cargo",
204+
}
205+
`;
206+
178207
exports[`extractResult() extracts benchmark output from cargo - criterion_output.txt 1`] = `
179208
{
180209
"benches": [

test/data/extract/cargo_output3.txt

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
running 0 tests
3+
4+
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
5+
6+
7+
running 2 tests
8+
test bench_fib_10 ... bench: 148.70 ns/iter (+/- 2.21)
9+
test bench_fib_20 ... bench: 18,794.12 ns/iter (+/- 440.25)
10+
11+
test result: ok. 0 passed; 0 failed; 0 ignored; 2 measured; 0 filtered out
12+

test/extract.spec.ts

+4
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ describe('extractResult()', function () {
6767
tool: 'cargo',
6868
file: 'cargo_output2.txt',
6969
},
70+
{
71+
tool: 'cargo',
72+
file: 'cargo_output3.txt',
73+
},
7074
{
7175
tool: 'cargo',
7276
file: 'criterion_output.txt',

0 commit comments

Comments
 (0)