0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/benchmark/misc/startup.js

37 lines
762 B
JavaScript
Raw Normal View History

'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');
2013-02-11 22:24:27 +01:00
const bench = common.createBenchmark(startNode, {
dur: [1]
2013-02-11 22:24:27 +01:00
});
function startNode({ dur }) {
2013-02-11 22:24:27 +01:00
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]);
2013-02-11 22:24:27 +01:00
node.on('exit', function(exitCode) {
if (exitCode !== 0) {
throw new Error('Error during node startup');
}
starts++;
if (go)
start();
else
bench.end(starts);
});
}
}