node/benchmark/child_process/child-process-exec-maxbuffer.js
Yagiz Nizipli 3fd0e1187d
benchmark: add child_process async path baselines
Add micro-benchmarks that isolate the hot paths targeted by the
JavaScript-to-C++ migration of child_process:

- child-process-spawn-options.js scales the env vars and args that
  ProcessWrap::Spawn must marshal across the JS/C++ boundary.
- child-process-ipc-roundtrip.js measures IPC throughput for both the
  json and advanced serializers across a range of payload sizes.
- child-process-exec-maxbuffer.js measures stdout accumulation and
  maxBuffer handling in execFile().

These establish the baseline that later migration PRs are compared
against. There is no runtime behavior change.

Signed-off-by: Yagiz Nizipli <yagiz@nizipli.com>
PR-URL: https://github.com/nodejs/node/pull/63929
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2026-06-17 16:08:56 +00:00

39 lines
1.1 KiB
JavaScript

'use strict';
const common = require('../common.js');
const { execFile } = require('child_process');
// Isolates stdout accumulation + maxBuffer handling in execFile(). The child
// writes `chunks` blocks of 64 KiB; the parent accumulates them through the
// native pipe read path and the JS buffering in lib/child_process.js until the
// process exits and the result buffer is handed to the callback.
const bench = common.createBenchmark(main, {
// Number of 64 KiB blocks written by the child: 1 MiB, 16 MiB, 64 MiB.
chunks: [16, 256, 1024],
n: [10],
});
function main({ n, chunks }) {
const script =
'const b = Buffer.alloc(65536, 0x61);' +
`for (let i = 0; i < ${chunks}; i++) process.stdout.write(b);`;
const args = ['-e', script];
const options = {
maxBuffer: chunks * 65536 + 65536,
encoding: 'buffer',
};
let left = n;
const run = () => {
execFile(process.execPath, args, options, (err) => {
if (err)
throw err;
if (--left === 0)
return bench.end(n);
run();
});
};
bench.start();
run();
}