From c41fef1ef104f4797cca45051774d4a662156f9a Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Wed, 21 Jan 2026 14:45:07 -0500 Subject: [PATCH] Nicer bench output (#17505) * test * dont coerce to string * more readable output for pnpm bench * oops * fix --- benchmarking/benchmarks/reactivity/sbench.js | 4 +- benchmarking/benchmarks/reactivity/util.js | 8 +-- .../benchmarks/ssr/wrapper/wrapper_bench.js | 4 +- benchmarking/run.js | 64 +++++++++++-------- package.json | 2 +- 5 files changed, 48 insertions(+), 34 deletions(-) diff --git a/benchmarking/benchmarks/reactivity/sbench.js b/benchmarking/benchmarks/reactivity/sbench.js index 47ff4a621a..9c41f60746 100644 --- a/benchmarking/benchmarks/reactivity/sbench.js +++ b/benchmarking/benchmarks/reactivity/sbench.js @@ -48,8 +48,8 @@ function create_sbench_test(label, count, num_sources, fn) { return { benchmark: label, - time: time.toFixed(2), - gc_time: gc_time.toFixed(2) + time, + gc_time }; }; } diff --git a/benchmarking/benchmarks/reactivity/util.js b/benchmarking/benchmarks/reactivity/util.js index ff0722d85e..6a2e44f5ae 100644 --- a/benchmarking/benchmarks/reactivity/util.js +++ b/benchmarking/benchmarks/reactivity/util.js @@ -35,8 +35,8 @@ export function create_test(label, setup) { return { benchmark: `${label}_unowned`, - time: time.toFixed(2), - gc_time: gc_time.toFixed(2) + time, + gc_time }; }, owned: async () => { @@ -65,8 +65,8 @@ export function create_test(label, setup) { return { benchmark: `${label}_owned`, - time: time.toFixed(2), - gc_time: gc_time.toFixed(2) + time, + gc_time }; } }; diff --git a/benchmarking/benchmarks/ssr/wrapper/wrapper_bench.js b/benchmarking/benchmarks/ssr/wrapper/wrapper_bench.js index 6fc992d4a2..6e790ee2b8 100644 --- a/benchmarking/benchmarks/ssr/wrapper/wrapper_bench.js +++ b/benchmarking/benchmarks/ssr/wrapper/wrapper_bench.js @@ -34,8 +34,8 @@ export async function wrapper_bench() { return { benchmark: 'wrapper_bench', - time: time.toFixed(2), - gc_time: gc_time.toFixed(2) + time, + gc_time }; } diff --git a/benchmarking/run.js b/benchmarking/run.js index bd96b9c2dc..f7b8128886 100644 --- a/benchmarking/run.js +++ b/benchmarking/run.js @@ -10,46 +10,60 @@ const suites = [ { benchmarks: ssr_benchmarks, name: 'server-side rendering benchmarks' } ]; -// eslint-disable-next-line no-console -console.log('\x1b[1m', '-- Benchmarking Started --', '\x1b[0m'); +const COLUMN_WIDTHS = [25, 9, 9]; +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); + try { for (const { benchmarks, name } of suites) { let suite_time = 0; let suite_gc_time = 0; - // eslint-disable-next-line no-console + 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) { const results = await benchmark(); - // eslint-disable-next-line no-console - console.log(results); - total_time += Number(results.time); - total_gc_time += Number(results.gc_time); - suite_time += Number(results.time); - suite_gc_time += Number(results.gc_time); + console.log( + pad_right(results.benchmark, COLUMN_WIDTHS[0]) + + pad_left(results.time.toFixed(2), COLUMN_WIDTHS[1]) + + pad_left(results.gc_time.toFixed(2), COLUMN_WIDTHS[2]) + ); + 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`); - - // eslint-disable-next-line no-console - console.log({ - suite_time: suite_time.toFixed(2), - suite_gc_time: suite_gc_time.toFixed(2) - }); + console.log('='.repeat(TOTAL_WIDTH)); + console.log( + pad_right('suite', COLUMN_WIDTHS[0]) + + pad_left(suite_time.toFixed(2), COLUMN_WIDTHS[1]) + + pad_left(suite_gc_time.toFixed(2), COLUMN_WIDTHS[2]) + ); + console.log('='.repeat(TOTAL_WIDTH)); } } catch (e) { - // eslint-disable-next-line no-console - console.log('\x1b[1m', '\n-- Benchmarking Failed --\n', '\x1b[0m'); // eslint-disable-next-line no-console console.error(e); process.exit(1); } + $.pop(); -// eslint-disable-next-line no-console -console.log('\x1b[1m', '\n-- Benchmarking Complete --\n', '\x1b[0m'); -// eslint-disable-next-line no-console -console.log({ - total_time: total_time.toFixed(2), - total_gc_time: total_gc_time.toFixed(2) -}); + +console.log(''); + +console.log( + pad_right('total', COLUMN_WIDTHS[0]) + + pad_left(total_time.toFixed(2), COLUMN_WIDTHS[1]) + + pad_left(total_gc_time.toFixed(2), COLUMN_WIDTHS[2]) +); diff --git a/package.json b/package.json index 12e59a2665..aa9c8cafa3 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ "test": "vitest run", "changeset:version": "changeset version && pnpm -r generate:version && git add --all", "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:debug": "node --allow-natives-syntax --inspect-brk ./benchmarking/run.js" },