| 23 | }); |
| 24 | |
| 25 | function spawnProcess(script, bench, state) { |
| 26 | const cmd = process.execPath || process.argv[0]; |
| 27 | while (state.finished < state.n) { |
| 28 | const child = spawnSync(cmd, script); |
| 29 | if (child.status !== 0) { |
| 30 | console.log('---- STDOUT ----'); |
| 31 | console.log(child.stdout.toString()); |
| 32 | console.log('---- STDERR ----'); |
| 33 | console.log(child.stderr.toString()); |
| 34 | throw new Error(`Child process stopped with exit code ${child.status}`); |
| 35 | } |
| 36 | state.finished++; |
| 37 | if (state.finished === 0) { |
| 38 | // Finished warmup. |
| 39 | bench.start(); |
| 40 | } |
| 41 | |
| 42 | if (state.finished === state.n) { |
| 43 | bench.end(state.n); |
| 44 | } |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | function main({ n, script, nFiles, prefixPath }) { |
| 49 | script = path.resolve(__dirname, '../../', `${script}.js`); |