summaryrefslogtreecommitdiff
path: root/benchmark/misc/startup.js
blob: 703146f081b3c6712f3684218879fa910ee48d0b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
'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);
    });
  }
}