Skip to content

Commit

Permalink
fix trailing whitespace characters in cargo benchmarks (#97)
Browse files Browse the repository at this point in the history
  • Loading branch information
ktrz authored Dec 31, 2021
1 parent 2eac1b8 commit fda486e
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ function extractCargoResult(output: string): BenchmarkResult[] {
continue;
}

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

Expand Down
4 changes: 4 additions & 0 deletions test/data/extract/cargo_output2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
test bench_engine_new ... bench: 211,834 ns/iter (+/- 70,126)
test bench_engine_new_raw ... bench: 197 ns/iter (+/- 18)
test bench_engine_new_raw_core ... bench: 196 ns/iter (+/- 31)
test bench_engine_register_fn ... bench: 493 ns/iter (+/- 82)
32 changes: 31 additions & 1 deletion test/extract.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,36 @@ describe('extractResult()', function () {
},
],
},
{
tool: 'cargo',
file: 'cargo_output2.txt',
expected: [
{
name: 'bench_engine_new',
range: '± 70126',
unit: 'ns/iter',
value: 211834,
},
{
name: 'bench_engine_new_raw',
range: '± 18',
unit: 'ns/iter',
value: 197,
},
{
name: 'bench_engine_new_raw_core',
range: '± 31',
unit: 'ns/iter',
value: 196,
},
{
name: 'bench_engine_register_fn',
range: '± 82',
unit: 'ns/iter',
value: 493,
},
],
},
{
tool: 'cargo',
file: 'criterion_output.txt',
Expand Down Expand Up @@ -346,7 +376,7 @@ describe('extractResult()', function () {
];

for (const test of normalCases) {
it(`extracts benchmark output from ${test.tool}`, async function () {
it(`extracts benchmark output from ${test.tool}${test.file ? ` - ${test.file}` : ''}`, async function () {
const file = test.file ?? `${test.tool}_output.txt`;
const outputFilePath = path.join(__dirname, 'data', 'extract', file);
const config = {
Expand Down

0 comments on commit fda486e

Please sign in to comment.