Skip to content

Commit

Permalink
Allow to parse generic cargo bench/criterion units
Browse files Browse the repository at this point in the history
  • Loading branch information
xtrm0 committed Nov 27, 2024
1 parent 6bae118 commit da695c6
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,8 @@ function extractCargoResult(output: string): BenchmarkResult[] {
const ret = [];
// Example:
// test bench_fib_20 ... bench: 37,174.25 ns/iter (+/- 7,527.43)
const reExtract = /^test (.+)\s+\.\.\. bench:\s+([0-9,.]+) ns\/iter \(\+\/- ([0-9,.]+)\)$/;

const reExtract = /^test (.+)\s+\.\.\. bench:\s+([0-9,.]+) (\w+\/\w+) \(\+\/- ([0-9,.]+)\)$/;
const reComma = /,/g;

for (const line of lines) {
Expand All @@ -326,13 +327,14 @@ function extractCargoResult(output: string): BenchmarkResult[] {

const name = m[1].trim();
const value = parseFloat(m[2].replace(reComma, ''));
const range = m[3].replace(reComma, '');
const unit = m[3].trim();
const range = m[4].replace(reComma, '');

ret.push({
name,
value,
range: ${range}`,
unit: 'ns/iter',
unit: unit,
});
}

Expand Down
47 changes: 47 additions & 0 deletions test/__snapshots__/extract.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,53 @@ exports[`extractResult() extracts benchmark output from cargo - cargo_output.txt
}
`;

exports[`extractResult() extracts benchmark output from cargo - cargo_output_units.txt 1`] = `
{
"benches": [
{
"name": "cmov",
"range": "± 14",
"unit": "cycles/iter",
"value": 2835,
},
{
"name": "cmov2",
"range": "± 19",
"unit": "cycles/iter",
"value": 2845,
},
{
"name": "mov",
"range": "± 17",
"unit": "cycles/iter",
"value": 1508,
},
{
"name": "upload",
"range": "± 420",
"unit": "MS/s",
"value": 1911,
},
{
"name": "download",
"range": "± 69",
"unit": "MS/s",
"value": 9001,
},
],
"commit": {
"author": null,
"committer": null,
"id": "123456789abcdef",
"message": "this is dummy",
"timestamp": "dummy timestamp",
"url": "https://github.com/dummy/repo",
},
"date": 1712131503296,
"tool": "cargo",
}
`;

exports[`extractResult() extracts benchmark output from cargo - cargo_output2.txt 1`] = `
{
"benches": [
Expand Down
9 changes: 9 additions & 0 deletions test/data/extract/cargo_output_units.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
test cmov ... bench: 2835 cycles/iter (+/- 14)

test cmov2 ... bench: 2845 cycles/iter (+/- 19)

test mov ... bench: 1508 cycles/iter (+/- 17)

test upload ... bench: 1911 MS/s (+/- 420)

test download ... bench: 9001 MS/s (+/- 69)
4 changes: 4 additions & 0 deletions test/extract.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ describe('extractResult()', function () {
tool: 'cargo',
file: 'cargo_output3.txt',
},
{
tool: 'cargo',
file: 'cargo_output_units.txt',
},
{
tool: 'cargo',
file: 'criterion_output.txt',
Expand Down

0 comments on commit da695c6

Please sign in to comment.