Skip to content

Commit b28b7aa

Browse files
bernedomspl
authored andcommitted
Extracting from catch2 supports long benchmark names
- Stitch together multiline names - Source: benchmark-action/github-action-benchmark#46
1 parent 5470751 commit b28b7aa

File tree

3 files changed

+49
-10
lines changed

3 files changed

+49
-10
lines changed

src/extract.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ function extractCatch2Result(output: string): BenchmarkResult[] {
390390
const reTestCaseStart = /^benchmark name +samples +iterations +estimated/;
391391
const reBenchmarkStart = /(\d+) +(\d+) +(?:\d+(\.\d+)?) (?:ns|ms|us|s)\s*$/;
392392
const reBenchmarkValues =
393-
/^ +(\d+(?:\.\d+)?) (ns|us|ms|s) +(?:\d+(?:\.\d+)?) (?:ns|us|ms|s) +(?:\d+(?:\.\d+)?) (?:ns|us|ms|s)/;
393+
/^(.*) +(\d+(?:\.\d+)?) (ns|us|ms|s) +(?:\d+(?:\.\d+)?) (?:ns|us|ms|s) +(?:\d+(?:\.\d+)?) (?:ns|us|ms|s)/;
394394
const reEmptyLine = /^\s*$/;
395395
const reSeparator = /^-+$/;
396396

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

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

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

428-
const value = parseFloat(mean[1]);
429-
const unit = mean[2];
428+
const nameAddition = mean[1].trim();
429+
if (nameAddition.trim() !== '') {
430+
name += ' ' + nameAddition.trim();
431+
}
432+
const value = parseFloat(mean[2]);
433+
const unit = mean[3];
430434

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

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

443447
// Skip empty line
444448
const [emptyLine, emptyLineNum] = nextLine();

test/data/extract/catch2_output.txt

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@ Catch2_bench is a Catch v2.11.0 host application.
44
Run with -? for options
55

66
-------------------------------------------------------------------------------
7-
Fibonacci
7+
Unit_assignment
8+
Construction
89
-------------------------------------------------------------------------------
910
/Users/rhayasd/Develop/github.com/rhysd/github-action-benchmark/examples/catch2/catch2_bench.cpp:5
1011
...............................................................................
1112

12-
benchmark name samples iterations estimated
13-
mean low mean high mean
14-
std dev low std dev high std dev
13+
benchmark name samples iterations estimated
14+
mean low mean high mean
15+
std dev low std dev high std dev
1516
-------------------------------------------------------------------------------
1617
Fibonacci 10 100 208 7.1968 ms
1718
344 ns 341 ns 349 ns
@@ -38,7 +39,27 @@ Fibonacci~ 5! 100 1961
3839

3940
Fibonacci-15_bench 100 20 7.48 ms
4041
3.789 us 3.734 us 3.888 us
41-
362 ns 234 ns 539 ns
42+
362 ns 234 ns 539 ns
43+
44+
-------------------------------------------------------------------------------
45+
Even More Fibonacci
46+
With a long name
47+
-------------------------------------------------------------------------------
48+
/Users/rhayasd/Develop/github.com/rhysd/github-action-benchmark/examples/catch2/catch2_bench.cpp:26
49+
...............................................................................
50+
51+
benchmark name samples iterations estimated
52+
mean low mean high mean
53+
std dev low std dev high std dev
54+
-------------------------------------------------------------------------------
55+
Fibonacci 10 with 100 208 7.1968 ms
56+
a long name 344 ns 341 ns 349 ns
57+
19 ns 11 ns 29 ns
58+
59+
Fibonacci 20 100 2 8.3712 ms
60+
41.731 us 41.25 us 42.622 us
61+
3.256 us 2.163 us 5.353 us
62+
4263

4364

4465
===============================================================================

test/extract.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,20 @@ describe('extractResult()', function () {
9898
value: 3.789,
9999
extra: '100 samples\n20 iterations',
100100
},
101+
{
102+
name: 'Fibonacci 10 with a long name',
103+
range: '± 19',
104+
unit: 'ns',
105+
value: 344,
106+
extra: '100 samples\n208 iterations',
107+
},
108+
{
109+
name: 'Fibonacci 20',
110+
range: '± 3.256',
111+
unit: 'us',
112+
value: 41.731,
113+
extra: '100 samples\n2 iterations',
114+
},
101115
],
102116
},
103117
{

0 commit comments

Comments
 (0)