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