Skip to content

Commit 072af25

Browse files
committed
chore: Use fork when -c is not set
1 parent d6349bb commit 072af25

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed

benchmark/compare.js

+19-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
const { spawn } = require('child_process');
3+
const { spawn, fork } = require('child_process');
44
const { inspect } = require('util');
55
const path = require('path');
66
const CLI = require('./_cli.js');
@@ -41,7 +41,7 @@ if (benchmarks.length === 0) {
4141
}
4242

4343
const cpuCoreSetting = cli.optional.set.find(s => s.startsWith('CPUCORE='));
44-
let cpuCore = '0';
44+
let cpuCore = null;
4545
if (cpuCoreSetting) {
4646
cpuCore = cpuCoreSetting.split('=')[1];
4747
}
@@ -76,12 +76,23 @@ if (showProgress) {
7676
(function recursive(i) {
7777
const job = queue[i];
7878

79-
const spawnArgs = ['-c', cpuCore, cli.optional[job.binary], path.resolve(__dirname, job.filename), ...cli.optional.set];
80-
81-
const child = spawn('taskset', spawnArgs, {
82-
env: process.env,
83-
stdio: ['inherit', 'pipe', 'inherit', 'ipc'],
84-
});
79+
const resolvedPath = path.resolve(__dirname, job.filename);
80+
let child;
81+
if (cpuCore !== null) {
82+
const spawnArgs = ['-c', cpuCore, cli.optional[job.binary], resolvedPath, ...cli.optional.set];
83+
child = spawn('taskset', spawnArgs, {
84+
env: process.env,
85+
stdio: ['inherit', 'pipe', 'ipc'],
86+
});
87+
88+
child.stdout.on('data', (data) => {
89+
process.stdout.write(data);
90+
});
91+
} else {
92+
child = fork(resolvedPath, cli.optional.set, {
93+
execPath: cli.optional[job.binary],
94+
});
95+
}
8596

8697
child.on('message', (data) => {
8798
if (data.type === 'report') {

benchmark/run.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ if (format === 'csv') {
5050
const args = cli.test ? ['--test'] : cli.optional.set;
5151

5252
const child = spawn('taskset', [`-c`, cpuCore, `node`, scriptPath, ...args], {
53-
stdio: ['inherit', 'pipe', 'inherit', 'ipc']
53+
stdio: ['inherit', 'pipe', 'ipc']
5454
});
5555

5656

@@ -82,6 +82,10 @@ if (format === 'csv') {
8282
}
8383
});
8484

85+
child.stdout.on('data', (data) => {
86+
process.stdout.write(data);
87+
});
88+
8589
child.once('close', (code) => {
8690
if (code) {
8791
process.exit(code);

0 commit comments

Comments
 (0)