Skip to content

Commit 4293202

Browse files
committed
[cli] bench: don't show "Stable Memory" table if all values are 0; latex diff color in CI env
1 parent 1bea771 commit 4293202

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

cli/commands/bench.ts

+20-2
Original file line numberDiff line numberDiff line change
@@ -263,24 +263,37 @@ async function runBenchFile(file : string, options : BenchOptions, replica : Ben
263263

264264
let getTable = (prop : keyof BenchResult) : string => {
265265
let resArr = [['', ...schema.cols]];
266+
let allZero = true;
266267

267268
for (let [_rowIndex, row] of schema.rows.entries()) {
268269
let curRow = [row];
269270

270271
for (let [_colIndex, col] of schema.cols.entries()) {
271272
let res = results.get(`${row}:${col}`);
272273
if (res) {
274+
if (res[prop] != 0n) {
275+
allZero = false;
276+
}
273277

274278
// compare with previous results
275279
let diff = '';
276280
if (options.compare && prevResults) {
277281
let prevRes = prevResults.get(`${row}:${col}`);
278282
if (prevRes) {
279283
let percent = (Number(res[prop]) - Number(prevRes[prop])) / Number(prevRes[prop]) * 100;
284+
if (Object.is(percent, NaN)) {
285+
percent = 0;
286+
}
280287
let sign = percent > 0 ? '+' : '';
281288
let percentText = percent == 0 ? '0%' : sign + percent.toFixed(2) + '%';
282289
let color : keyof typeof chalk = percent == 0 ? 'gray' : (percent > 0 ? 'red' : 'green');
283-
diff = ` (${chalk[color](percentText)})`;
290+
if (process.env.CI) {
291+
// diff = ` (<span style="color:${color}">${percentText}</span>)`;
292+
diff = ` (\${\\color{${color}}${percentText.replace('%', '\\\\%')}}$)`;
293+
}
294+
else {
295+
diff = ` (${chalk[color](percentText)})`;
296+
}
284297
}
285298
else {
286299
diff = chalk.yellow(' (no previous results)');
@@ -307,6 +320,11 @@ async function runBenchFile(file : string, options : BenchOptions, replica : Ben
307320
resArr.push(curRow);
308321
}
309322

323+
// don't show Stable Memory table if all values are 0
324+
if (allZero && prop == 'rts_logical_stable_memory_size') {
325+
return '';
326+
}
327+
310328
return markdownTable(resArr, {
311329
align: ['l', ...'r'.repeat(schema.cols.length)],
312330
stringLength: stringWidth,
@@ -322,7 +340,7 @@ async function runBenchFile(file : string, options : BenchOptions, replica : Ben
322340
\n\n${chalk.blue('Instructions')}\n\n${getTable('instructions')}
323341
\n\n${chalk.blue('Heap')}\n\n${getTable('rts_heap_size')}
324342
\n\n${chalk.blue('Garbage Collection')}\n\n${getTable('rts_reclaimed')}
325-
\n\n${chalk.blue('Stable Memory')}\n\n${getTable('rts_logical_stable_memory_size')}
343+
${getTable('rts_logical_stable_memory_size') ? `\n\n${chalk.blue('Stable Memory')}\n\n${getTable('rts_logical_stable_memory_size')}` : ''}
326344
`;
327345
};
328346

0 commit comments

Comments
 (0)