Nicer bench output (#17505)

* test

* dont coerce to string

* more readable output for pnpm bench

* oops

* fix
pull/17507/head
Rich Harris 8 months ago committed by GitHub
parent 46c810ce71
commit c41fef1ef1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -48,8 +48,8 @@ function create_sbench_test(label, count, num_sources, fn) {
return { return {
benchmark: label, benchmark: label,
time: time.toFixed(2), time,
gc_time: gc_time.toFixed(2) gc_time
}; };
}; };
} }

@ -35,8 +35,8 @@ export function create_test(label, setup) {
return { return {
benchmark: `${label}_unowned`, benchmark: `${label}_unowned`,
time: time.toFixed(2), time,
gc_time: gc_time.toFixed(2) gc_time
}; };
}, },
owned: async () => { owned: async () => {
@ -65,8 +65,8 @@ export function create_test(label, setup) {
return { return {
benchmark: `${label}_owned`, benchmark: `${label}_owned`,
time: time.toFixed(2), time,
gc_time: gc_time.toFixed(2) gc_time
}; };
} }
}; };

@ -34,8 +34,8 @@ export async function wrapper_bench() {
return { return {
benchmark: 'wrapper_bench', benchmark: 'wrapper_bench',
time: time.toFixed(2), time,
gc_time: gc_time.toFixed(2) gc_time
}; };
} }

@ -10,46 +10,60 @@ const suites = [
{ benchmarks: ssr_benchmarks, name: 'server-side rendering benchmarks' } { benchmarks: ssr_benchmarks, name: 'server-side rendering benchmarks' }
]; ];
// eslint-disable-next-line no-console const COLUMN_WIDTHS = [25, 9, 9];
console.log('\x1b[1m', '-- Benchmarking Started --', '\x1b[0m'); const TOTAL_WIDTH = COLUMN_WIDTHS.reduce((a, b) => a + b);
const pad_right = (str, n) => str + ' '.repeat(n - str.length);
const pad_left = (str, n) => ' '.repeat(n - str.length) + str;
$.push({}, true); $.push({}, true);
try { try {
for (const { benchmarks, name } of suites) { for (const { benchmarks, name } of suites) {
let suite_time = 0; let suite_time = 0;
let suite_gc_time = 0; let suite_gc_time = 0;
// eslint-disable-next-line no-console
console.log(`\nRunning ${name}...\n`); console.log(`\nRunning ${name}...\n`);
console.log(
pad_right('Benchmark', COLUMN_WIDTHS[0]) +
pad_left('Time', COLUMN_WIDTHS[1]) +
pad_left('GC time', COLUMN_WIDTHS[2])
);
console.log('='.repeat(TOTAL_WIDTH));
for (const benchmark of benchmarks) { for (const benchmark of benchmarks) {
const results = await benchmark(); const results = await benchmark();
// eslint-disable-next-line no-console console.log(
console.log(results); pad_right(results.benchmark, COLUMN_WIDTHS[0]) +
total_time += Number(results.time); pad_left(results.time.toFixed(2), COLUMN_WIDTHS[1]) +
total_gc_time += Number(results.gc_time); pad_left(results.gc_time.toFixed(2), COLUMN_WIDTHS[2])
suite_time += Number(results.time); );
suite_gc_time += Number(results.gc_time); total_time += results.time;
total_gc_time += results.gc_time;
suite_time += results.time;
suite_gc_time += results.gc_time;
} }
console.log(`\nFinished ${name}.\n`); console.log('='.repeat(TOTAL_WIDTH));
console.log(
// eslint-disable-next-line no-console pad_right('suite', COLUMN_WIDTHS[0]) +
console.log({ pad_left(suite_time.toFixed(2), COLUMN_WIDTHS[1]) +
suite_time: suite_time.toFixed(2), pad_left(suite_gc_time.toFixed(2), COLUMN_WIDTHS[2])
suite_gc_time: suite_gc_time.toFixed(2) );
}); console.log('='.repeat(TOTAL_WIDTH));
} }
} catch (e) { } catch (e) {
// eslint-disable-next-line no-console
console.log('\x1b[1m', '\n-- Benchmarking Failed --\n', '\x1b[0m');
// eslint-disable-next-line no-console // eslint-disable-next-line no-console
console.error(e); console.error(e);
process.exit(1); process.exit(1);
} }
$.pop(); $.pop();
// eslint-disable-next-line no-console
console.log('\x1b[1m', '\n-- Benchmarking Complete --\n', '\x1b[0m'); console.log('');
// eslint-disable-next-line no-console
console.log({ console.log(
total_time: total_time.toFixed(2), pad_right('total', COLUMN_WIDTHS[0]) +
total_gc_time: total_gc_time.toFixed(2) pad_left(total_time.toFixed(2), COLUMN_WIDTHS[1]) +
}); pad_left(total_gc_time.toFixed(2), COLUMN_WIDTHS[2])
);

@ -21,7 +21,7 @@
"test": "vitest run", "test": "vitest run",
"changeset:version": "changeset version && pnpm -r generate:version && git add --all", "changeset:version": "changeset version && pnpm -r generate:version && git add --all",
"changeset:publish": "changeset publish", "changeset:publish": "changeset publish",
"bench": "node --allow-natives-syntax ./benchmarking/run.js", "bench": "NODE_ENV=production node --allow-natives-syntax ./benchmarking/run.js",
"bench:compare": "node --allow-natives-syntax ./benchmarking/compare/index.js", "bench:compare": "node --allow-natives-syntax ./benchmarking/compare/index.js",
"bench:debug": "node --allow-natives-syntax --inspect-brk ./benchmarking/run.js" "bench:debug": "node --allow-natives-syntax --inspect-brk ./benchmarking/run.js"
}, },

Loading…
Cancel
Save