Skip to content

Commit 36a40d6

Browse files
authored
Merge pull request #13 from cryspen/wysiwys/more-flexible-input
Update accepted format
2 parents 72d76dc + 412112b commit 36a40d6

File tree

9 files changed

+74
-214
lines changed

9 files changed

+74
-214
lines changed

.github/workflows/build-and-test.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,22 @@ jobs:
2121
tool: 'cargo'
2222
os: 'ubuntu-latest'
2323
output-file-path: ./test/data/extract/cargo_output.txt
24-
data-out-path: output.txt
24+
data-out-path: output.json
2525
- uses: ./ # local action in repo
2626
with:
2727
tool: 'cargo'
2828
os: 'ubuntu-latest'
2929
output-file-path: ./test/data/extract/cargo_output2.txt
30-
data-out-path: output.txt
30+
data-out-path: output.json
3131
- uses: ./ # local action in repo
3232
with:
3333
tool: 'cargo'
3434
os: 'ubuntu-latest'
3535
output-file-path: ./test/data/extract/cargo_output3.txt
36-
data-out-path: output.txt
36+
data-out-path: output.json
3737
- uses: ./ # local action in repo
3838
with:
3939
tool: 'cargo'
4040
os: 'ubuntu-latest'
4141
output-file-path: ./test/data/extract/criterion_output.txt
42-
data-out-path: output.txt
42+
data-out-path: output.json

.github/workflows/minimal.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ jobs:
1818
tool: 'cargo'
1919
os: 'ubuntu-latest'
2020
output-file-path: ./test/data/extract/cargo_output.txt
21-
data-out-path: output.txt
21+
data-out-path: output.json

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ Currently supported sources:
1515

1616
## Metadata format
1717

18-
The benchmark name in the `cargo` benchmarks can be provided as a `/`-separated string with the format `category/key size/name/platform/api`. The key size should be an integer. Some fields in this string can be left blank. Any unspecified or invalid fields will be parsed to `undefined`.
18+
The benchmark name in the `cargo` benchmarks can be provided as a `,`-separated string where each item represents a key-value pair with the format `key=value`, e.g. `category=ML-KEM,keySize=44,name=PK Validation,platform=neon,api=unpacked`.
19+
20+
Alternatively, the benchmark name can be provided as a simple string, which will then be set as the value of the `name` key. This will only happen if there are no `key=value` pairs found in the benchmark name.
1921

2022
## Output data format
2123

src/extract.ts

Lines changed: 33 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -9,88 +9,61 @@ export interface BenchmarkResult {
99
extra?: string;
1010
os: string;
1111

12-
// from NameMetadata
13-
category: string | undefined;
14-
keySize: number | undefined;
15-
name: string;
16-
platform: string | undefined;
17-
api: string | undefined;
12+
// from metadata
13+
[key: string]: any;
1814
}
1915

20-
interface NameMetadata {
21-
category: string | undefined;
22-
keySize: number | undefined;
23-
name: string;
24-
platform: string | undefined;
25-
api: string | undefined;
26-
}
27-
function extractMetadataFromName(name_string: string): NameMetadata {
16+
function addNameMetadataToResult(result: BenchmarkResult, nameString: string) {
2817
// split by separator
29-
const values = name_string.split('/');
30-
31-
// if only one arg provided, just return name
32-
if (values.length === 1) {
33-
const name = name_string;
34-
return { name, keySize: undefined, category: undefined, platform: undefined, api: undefined };
35-
}
18+
const keyValuePairs = nameString.split(',');
3619

37-
// extract by position
38-
const category = values[0] === '' ? undefined : values[0];
20+
let foundAtLeastOne = false;
3921

40-
// If keySize not a number, use `undefined`
41-
const keySizeParsed = parseInt(values[1]);
42-
43-
const keySize = isNaN(keySizeParsed) ? undefined : keySizeParsed;
22+
for (const pair of keyValuePairs) {
23+
const items = pair.split('=');
24+
if (items.length !== 2) {
25+
// invalid key-value pair
26+
continue;
27+
}
28+
const [key, value] = items;
29+
result[key] = value;
4430

45-
// if name is not defined, keep entire name_string as name
46-
let name = values[2];
47-
if (name === undefined || name === '') {
48-
name = name_string;
31+
// at least one key-value pair was found
32+
foundAtLeastOne = true;
4933
}
5034

51-
const platform = values[3] === '' ? undefined : values[3];
52-
const api = values[4] === '' ? undefined : values[4];
53-
54-
return {
55-
category,
56-
keySize,
57-
name,
58-
platform,
59-
api,
60-
};
35+
if (!foundAtLeastOne) {
36+
// no key-value pairs found in string
37+
// return the entire string as the name
38+
result.name = nameString;
39+
}
6140
}
6241

6342
function extractCargoResult(config: Config, output: string): BenchmarkResult[] {
6443
const lines = output.split(/\r?\n/g);
6544
const ret = [];
66-
const reExtract = /^test (.+)\s+\.\.\. bench:\s+([0-9,.]+) (\w+\/\w+) \(\+\/- ([0-9,.]+)\)$/;
45+
46+
const reExtract = /^test (.+)\s+\.\.\. bench:\s+([0-9,.]+) ([0-9A-Za-z_\u03BC]+\/\w+)( \(\+\/- [0-9,.]+\))?$/;
6747
const reComma = /,/g;
6848

6949
for (const line of lines) {
7050
const m = line.match(reExtract);
7151
if (m === null) {
7252
continue;
7353
}
74-
75-
const name_string = m[1].trim();
7654
const value = parseFloat(m[2].replace(reComma, ''));
7755
const unit = m[3].trim();
78-
const range = m[4].replace(reComma, '');
79-
80-
// TODO: error handling
81-
const { category, keySize, name, platform, api } = extractMetadataFromName(name_string);
82-
83-
ret.push({
84-
value,
85-
range: ${range}`,
86-
unit: unit,
87-
os: config.os,
88-
category,
89-
keySize,
90-
name,
91-
platform,
92-
api,
93-
});
56+
57+
// if the range is provided, replace the prefix, the suffix, and any commas.
58+
const range = m[4] ? m[4].replace(reComma, '').replace(' (+/- ', '± ').replace(')', '') : undefined;
59+
60+
const name_string = m[1].trim();
61+
62+
const result = { value, range, unit, os: config.os };
63+
64+
addNameMetadataToResult(result, name_string);
65+
66+
ret.push(result);
9467
}
9568

9669
return ret;

0 commit comments

Comments
 (0)