Skip to content

Commit d6349bb

Browse files
committed
feat: Taskset support for benchmarks
1 parent 27493a1 commit d6349bb

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

benchmark/compare.js

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

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

43+
const cpuCoreSetting = cli.optional.set.find(s => s.startsWith('CPUCORE='));
44+
let cpuCore = '0';
45+
if (cpuCoreSetting) {
46+
cpuCore = cpuCoreSetting.split('=')[1];
47+
}
48+
4349
// Create queue from the benchmarks list such both node versions are tested
4450
// `runs` amount of times each.
4551
// Note: BenchmarkProgress relies on this order to estimate
@@ -70,8 +76,11 @@ if (showProgress) {
7076
(function recursive(i) {
7177
const job = queue[i];
7278

73-
const child = fork(path.resolve(__dirname, job.filename), cli.optional.set, {
74-
execPath: cli.optional[job.binary],
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'],
7584
});
7685

7786
child.on('message', (data) => {

benchmark/run.js

+14-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22

33
const path = require('path');
4-
const fork = require('child_process').fork;
4+
const spawn = require('child_process').spawn;
55
const CLI = require('./_cli.js');
66

77
const cli = new CLI(`usage: ./node run.js [options] [--] <category> ...
@@ -34,16 +34,25 @@ if (!validFormats.includes(format)) {
3434
return;
3535
}
3636

37+
const cpuCoreSetting = cli.optional.set.find(s => s.startsWith('CPUCORE='));
38+
let cpuCore = '0';
39+
if (cpuCoreSetting) {
40+
cpuCore = cpuCoreSetting.split('=')[1];
41+
}
42+
3743
if (format === 'csv') {
3844
console.log('"filename", "configuration", "rate", "time"');
3945
}
4046

4147
(function recursive(i) {
4248
const filename = benchmarks[i];
43-
const child = fork(
44-
path.resolve(__dirname, filename),
45-
cli.test ? ['--test'] : cli.optional.set,
46-
);
49+
const scriptPath = path.resolve(__dirname, filename);
50+
const args = cli.test ? ['--test'] : cli.optional.set;
51+
52+
const child = spawn('taskset', [`-c`, cpuCore, `node`, scriptPath, ...args], {
53+
stdio: ['inherit', 'pipe', 'inherit', 'ipc']
54+
});
55+
4756

4857
if (format !== 'csv') {
4958
console.log();

0 commit comments

Comments
 (0)