Skip to content

Commit

Permalink
add tests and fix issue with parsing number as int instead of float
Browse files Browse the repository at this point in the history
  • Loading branch information
ktrz committed May 19, 2024
1 parent 5a8f9bf commit 731956c
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ function extractCargoResult(output: string): BenchmarkResult[] {
const lines = output.split(/\r?\n/g);
const ret = [];
// Example:
// test bench_fib_20 ... bench: 37,174 ns/iter (+/- 7,527)
// 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 reComma = /,/g;

Expand All @@ -325,7 +325,7 @@ function extractCargoResult(output: string): BenchmarkResult[] {
}

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

ret.push({
Expand Down
29 changes: 29 additions & 0 deletions test/__snapshots__/extract.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,35 @@ exports[`extractResult() extracts benchmark output from cargo - cargo_output2.tx
}
`;

exports[`extractResult() extracts benchmark output from cargo - cargo_output3.txt 1`] = `
{
"benches": [
{
"name": "bench_fib_10",
"range": "± 2.21",
"unit": "ns/iter",
"value": 148.7,
},
{
"name": "bench_fib_20",
"range": "± 440.25",
"unit": "ns/iter",
"value": 18794.12,
},
],
"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 - criterion_output.txt 1`] = `
{
"benches": [
Expand Down
12 changes: 12 additions & 0 deletions test/data/extract/cargo_output3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out


running 2 tests
test bench_fib_10 ... bench: 148.70 ns/iter (+/- 2.21)
test bench_fib_20 ... bench: 18,794.12 ns/iter (+/- 440.25)

test result: ok. 0 passed; 0 failed; 0 ignored; 2 measured; 0 filtered out

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

0 comments on commit 731956c

Please sign in to comment.