0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-30 07:27:22 +01:00
nodejs/benchmark/misc/startup.js
Ruben Bridgewater fd45187d34
benchmark: (misc) use destructuring
PR-URL: https://github.com/nodejs/node/pull/18250
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2018-01-23 01:29:27 +01:00

37 lines
762 B
JavaScript

'use strict';
const common = require('../common.js');
const spawn = require('child_process').spawn;
const path = require('path');
const emptyJsFile = path.resolve(__dirname, '../../test/fixtures/semicolon.js');
const bench = common.createBenchmark(startNode, {
dur: [1]
});
function startNode({ dur }) {
var go = true;
var starts = 0;
setTimeout(function() {
go = false;
}, dur * 1000);
bench.start();
start();
function start() {
const node = spawn(process.execPath || process.argv[0], [emptyJsFile]);
node.on('exit', function(exitCode) {
if (exitCode !== 0) {
throw new Error('Error during node startup');
}
starts++;
if (go)
start();
else
bench.end(starts);
});
}
}