diff --git a/benchmark/compare.js b/benchmark/compare.js index 503901f607ef02..ddf170cb6805c1 100644 --- a/benchmark/compare.js +++ b/benchmark/compare.js @@ -1,6 +1,6 @@ 'use strict'; -const { fork } = require('child_process'); +const { spawn, fork } = require('child_process'); const { inspect } = require('util'); const path = require('path'); const CLI = require('./_cli.js'); @@ -40,6 +40,12 @@ if (benchmarks.length === 0) { return; } +const cpuCoreSetting = cli.optional.set.find(s => s.startsWith('CPUCORE=')); +let cpuCore = null; +if (cpuCoreSetting) { + cpuCore = cpuCoreSetting.split('=')[1]; +} + // Create queue from the benchmarks list such both node versions are tested // `runs` amount of times each. // Note: BenchmarkProgress relies on this order to estimate @@ -70,9 +76,23 @@ if (showProgress) { (function recursive(i) { const job = queue[i]; - const child = fork(path.resolve(__dirname, job.filename), cli.optional.set, { - execPath: cli.optional[job.binary], - }); + const resolvedPath = path.resolve(__dirname, job.filename); + let child; + if (cpuCore !== null) { + const spawnArgs = ['-c', cpuCore, cli.optional[job.binary], resolvedPath, ...cli.optional.set]; + child = spawn('taskset', spawnArgs, { + env: process.env, + stdio: ['inherit', 'pipe', 'ipc'], + }); + + child.stdout.on('data', (data) => { + process.stdout.write(data); + }); + } else { + child = fork(resolvedPath, cli.optional.set, { + execPath: cli.optional[job.binary], + }); + } child.on('message', (data) => { if (data.type === 'report') { diff --git a/benchmark/run.js b/benchmark/run.js index 0b63fb930bb000..09333a4bda1818 100644 --- a/benchmark/run.js +++ b/benchmark/run.js @@ -1,7 +1,7 @@ 'use strict'; const path = require('path'); -const fork = require('child_process').fork; +const { spawn, fork } = require('child_process'); const CLI = require('./_cli.js'); const cli = new CLI(`usage: ./node run.js [options] [--] ... @@ -34,16 +34,37 @@ if (!validFormats.includes(format)) { return; } +const cpuCoreSetting = cli.optional.set.find(s => s.startsWith('CPUCORE=')); +let cpuCore = null; +if (cpuCoreSetting) { + cpuCore = cpuCoreSetting.split('=')[1]; +} + if (format === 'csv') { console.log('"filename", "configuration", "rate", "time"'); } (function recursive(i) { const filename = benchmarks[i]; - const child = fork( - path.resolve(__dirname, filename), - cli.test ? ['--test'] : cli.optional.set, - ); + const scriptPath = path.resolve(__dirname, filename); + const args = cli.test ? ['--test'] : cli.optional.set; + + let child; + + if (cpuCore !== null) { + child = spawn('taskset', [`-c`, cpuCore, `node`, scriptPath, ...args], { + stdio: ['inherit', 'pipe', 'ipc'] + }); + + child.stdout.on('data', (data) => { + process.stdout.write(data); + }); + } else { + child = fork( + scriptPath, + args, + ); + } if (format !== 'csv') { console.log();