Skip to content

Commit b7de0af

Browse files
committed
Update benchmark compare script.
- Add "present" mode to only show env items that are present. - Change label handling. - Fix various bugs and data handling issues.
1 parent 2b5aa2d commit b7de0af

File tree

2 files changed

+72
-16
lines changed

2 files changed

+72
-16
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
- Conditionally load test suites.
1717
- Fix various minor bugs.
1818
- Add multiple jobs benchmarking support.
19+
- Update benchmark compare script.
1920

2021
### Fixed
2122
- Improve safe mode for `@graph` use cases.

benchmarks/compare/compare.js

Lines changed: 71 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ yargs(hideBin(process.argv))
2727
})
2828
.option('env', {
2929
alias: 'e',
30-
choices: ['none', 'all', 'combined'],
30+
choices: ['none', 'all', 'present', 'combined'],
3131
default: 'none',
3232
description: 'Output environment format'
3333
})
@@ -50,18 +50,22 @@ async function compare({
5050
fn: f,
5151
content: await fs.readFile(f, 'utf8')
5252
})));
53+
//console.log(contents);
5354
const results = contents
5455
.map(c => ({
5556
fn: c.fn,
5657
content: JSON.parse(c.content),
5758
// map of test id => assertion
5859
testMap: new Map()
5960
}))
61+
.map(c => {
62+
//console.log('C', c);
63+
return c;
64+
})
6065
.map(c => ({
6166
...c,
62-
// FIXME process properly
63-
env: c.content['@included'][0],
64-
label: c.content['@included'][0]['jldb:label']
67+
env: c.content['@included']?.[0] || {},
68+
label: c.content['@included']?.[0]?.['jldb:label']
6569
}));
6670
//console.log(JSON.stringify(results, null, 2));
6771
// order of tests found in each result set
@@ -96,14 +100,17 @@ async function compare({
96100
hz(r.testMap.get(t))))
97101
.map(d => relative ? d.toFixed(2) + '%' : d.toFixed(2))
98102
]);
99-
//console.log(compared);
100-
//console.log(results);
103+
//console.log('COMPARED', compared);
104+
//console.log('RESULTS', results);
101105
const fnprefixlen = commonPathPrefix(file).length;
106+
function label(res) {
107+
return res.label || res.fn.slice(fnprefixlen);
108+
}
102109
console.log('## Comparison');
103110
console.log(markdownTable([
104111
[
105112
'Test',
106-
...results.map(r => r.label || r.fn.slice(fnprefixlen))
113+
...results.map(label)
107114
],
108115
...compared
109116
], {
@@ -130,15 +137,58 @@ async function compare({
130137
['Comment', 'jldb:comment']
131138
];
132139

140+
// show all properites
133141
if(env === 'all') {
134142
console.log();
135143
console.log('## Environment');
136-
console.log(markdownTable([
137-
envProps.map(p => p[0]),
138-
...results.map(r => envProps.map(p => r.env[p[1]] || ''))
144+
//const data = results.map(r => envProps.map(p => {
145+
// return (p[1] === 'jldb:label') ? label(r) : r.env[p[1]] || '';
146+
//}));
147+
const data = results.map(r => [
148+
label(r),
149+
...envProps.slice(1).map(p => r.env[p[1]] || '')
150+
]);
151+
if(data.length > 0) {
152+
console.log(markdownTable([
153+
envProps.map(p => p[0]),
154+
...data
155+
]));
156+
} else {
157+
console.log('*not specified*');
158+
}
159+
}
160+
161+
// show present properites
162+
if(env === 'present') {
163+
console.log();
164+
console.log('## Environment');
165+
// get all data
166+
const data = results.map(r => [
167+
label(r),
168+
...envProps.slice(1).map(p => r.env[p[1]] || '')
169+
]);
170+
// count present truthy fields per col
171+
const propCounts = envProps.slice(1)
172+
.map(p => results.reduce((c, r) => r.env[p[1]] ? ++c : c, 0));
173+
const presentProps = [
174+
envProps[0],
175+
...envProps.slice(1).filter((v, i) => propCounts[i] > 0)
176+
];
177+
const presentData = data.map(d => ([
178+
d[0],
179+
...d.slice(1).filter((v, i) => propCounts[i] > 0)
139180
]));
181+
if(data.length > 0) {
182+
console.log(markdownTable([
183+
presentProps.map(p => p[0]),
184+
...presentData
185+
]));
186+
} else {
187+
console.log('*not specified*');
188+
}
140189
}
141190

191+
// show combined grouping of properties
142192
if(env === 'combined') {
143193
console.log();
144194
console.log('## Environment');
@@ -149,11 +199,16 @@ async function compare({
149199
);
150200
return [key, values.size ? [...values].join(', ') : []];
151201
}
152-
console.log(markdownTable([
153-
['Key', 'Values'],
154-
...envProps
155-
.map(p => envline(p[0], p[1]))
156-
.filter(p => p[1].length)
157-
]));
202+
const data = envProps
203+
.map(p => envline(p[0], p[1]))
204+
.filter(p => p[1].length);
205+
if(data.length > 0) {
206+
console.log(markdownTable([
207+
['Key', 'Values'],
208+
...data
209+
]));
210+
} else {
211+
console.log('*not specified*');
212+
}
158213
}
159214
}

0 commit comments

Comments
 (0)