Skip to content

Commit

Permalink
Extracting from catch2 supports long benchmark names
Browse files Browse the repository at this point in the history
- Stitch together multiline names
- Source: benchmark-action/github-action-benchmark#46
  • Loading branch information
bernedom authored and spl committed Aug 5, 2021
1 parent 5470751 commit b28b7aa
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 10 deletions.
14 changes: 9 additions & 5 deletions src/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ function extractCatch2Result(output: string): BenchmarkResult[] {
const reTestCaseStart = /^benchmark name +samples +iterations +estimated/;
const reBenchmarkStart = /(\d+) +(\d+) +(?:\d+(\.\d+)?) (?:ns|ms|us|s)\s*$/;
const reBenchmarkValues =
/^ +(\d+(?:\.\d+)?) (ns|us|ms|s) +(?:\d+(?:\.\d+)?) (?:ns|us|ms|s) +(?:\d+(?:\.\d+)?) (?:ns|us|ms|s)/;
/^(.*) +(\d+(?:\.\d+)?) (ns|us|ms|s) +(?:\d+(?:\.\d+)?) (?:ns|us|ms|s) +(?:\d+(?:\.\d+)?) (?:ns|us|ms|s)/;
const reEmptyLine = /^\s*$/;
const reSeparator = /^-+$/;

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

const extra = `${start[1]} samples\n${start[2]} iterations`;
const name = startLine.slice(0, start.index).trim();
let name = startLine.slice(0, start.index).trim();

const [meanLine, meanLineNum] = nextLine();
const mean = meanLine?.match(reBenchmarkValues);
Expand All @@ -425,8 +425,12 @@ function extractCatch2Result(output: string): BenchmarkResult[] {
);
}

const value = parseFloat(mean[1]);
const unit = mean[2];
const nameAddition = mean[1].trim();
if (nameAddition.trim() !== '') {
name += ' ' + nameAddition.trim();
}
const value = parseFloat(mean[2]);
const unit = mean[3];

const [stdDevLine, stdDevLineNum] = nextLine();
const stdDev = stdDevLine?.match(reBenchmarkValues);
Expand All @@ -438,7 +442,7 @@ function extractCatch2Result(output: string): BenchmarkResult[] {
);
}

const range = '± ' + stdDev[1].trim();
const range = '± ' + stdDev[2].trim();

// Skip empty line
const [emptyLine, emptyLineNum] = nextLine();
Expand Down
31 changes: 26 additions & 5 deletions test/data/extract/catch2_output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ Catch2_bench is a Catch v2.11.0 host application.
Run with -? for options

-------------------------------------------------------------------------------
Fibonacci
Unit_assignment
Construction
-------------------------------------------------------------------------------
/Users/rhayasd/Develop/github.com/rhysd/github-action-benchmark/examples/catch2/catch2_bench.cpp:5
...............................................................................

benchmark name samples iterations estimated
mean low mean high mean
std dev low std dev high std dev
benchmark name samples iterations estimated
mean low mean high mean
std dev low std dev high std dev
-------------------------------------------------------------------------------
Fibonacci 10 100 208 7.1968 ms
344 ns 341 ns 349 ns
Expand All @@ -38,7 +39,27 @@ Fibonacci~ 5! 100 1961

Fibonacci-15_bench 100 20 7.48 ms
3.789 us 3.734 us 3.888 us
362 ns 234 ns 539 ns
362 ns 234 ns 539 ns

-------------------------------------------------------------------------------
Even More Fibonacci
With a long name
-------------------------------------------------------------------------------
/Users/rhayasd/Develop/github.com/rhysd/github-action-benchmark/examples/catch2/catch2_bench.cpp:26
...............................................................................

benchmark name samples iterations estimated
mean low mean high mean
std dev low std dev high std dev
-------------------------------------------------------------------------------
Fibonacci 10 with 100 208 7.1968 ms
a long name 344 ns 341 ns 349 ns
19 ns 11 ns 29 ns

Fibonacci 20 100 2 8.3712 ms
41.731 us 41.25 us 42.622 us
3.256 us 2.163 us 5.353 us



===============================================================================
Expand Down
14 changes: 14 additions & 0 deletions test/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,20 @@ describe('extractResult()', function () {
value: 3.789,
extra: '100 samples\n20 iterations',
},
{
name: 'Fibonacci 10 with a long name',
range: '± 19',
unit: 'ns',
value: 344,
extra: '100 samples\n208 iterations',
},
{
name: 'Fibonacci 20',
range: '± 3.256',
unit: 'us',
value: 41.731,
extra: '100 samples\n2 iterations',
},
],
},
{
Expand Down

0 comments on commit b28b7aa

Please sign in to comment.