From 2aa5dbb32d15e804bb1c5f3de8cb8f6d8a09245b Mon Sep 17 00:00:00 2001 From: luojiyin Date: Sun, 13 Sep 2026 12:17:38 +0800 Subject: [PATCH] refactor(benchmark): measure the built CLI instead of tsx benchmark-memory.mjs now runs: node lib/src/lint-md.js instead of: node tsx src/lint-md.ts This eliminates tsx runtime overhead and matches real npm usage. The worker thread path is now fully compiled JS, not a fallback. Also adds BSD-style /usr/bin/time output parsing as fallback. Requires `npm run build` before running the benchmark. --- scripts/benchmark-memory.mjs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/scripts/benchmark-memory.mjs b/scripts/benchmark-memory.mjs index 8e1112f..3dab166 100644 --- a/scripts/benchmark-memory.mjs +++ b/scripts/benchmark-memory.mjs @@ -18,6 +18,8 @@ const usage = `Usage: node scripts/benchmark-memory.mjs [options] Linux only: requires GNU /usr/bin/time -v. +Runs the built CLI (lib/src/lint-md.js). Run \`npm run build\` first. + Options: --files Number of generated Markdown files (default: 8) --bytes-per-file Approximate bytes per file (default: 65536) @@ -118,12 +120,15 @@ try { filePaths.push(filePath); } - const tsx = path.join(rootDir, 'node_modules/tsx/dist/cli.mjs'); - const cli = path.join(rootDir, 'src/lint-md.ts'); + const cli = path.join(rootDir, 'lib/src/lint-md.js'); + if (!existsSync(cli)) { + throw new Error( + `Built CLI not found at ${cli}. Run \`npm run build\` first.` + ); + } + const cliArgs = [ - '-v', process.execPath, - tsx, cli, '--threads', String(options.threads), @@ -172,10 +177,10 @@ try { const rssMatch = result.stderr.match( /Maximum resident set size \(kbytes\): (\d+)/ - ); + ) || result.stderr.match(/(\d+)maxresident\)k/); const elapsedMatch = result.stderr.match( /Elapsed \(wall clock\) time \(h:mm:ss or m:ss\): ([\d:.]+)/ - ); + ) || result.stderr.match(/([\d:.]+)elapsed/); measurements.push({ run,