summaryrefslogtreecommitdiff
path: root/benchmark/vm/run-in-context.js
blob: 9b57067a19c9ac28aad407ef28426b030fc8eb3a (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
'use strict';

const common = require('../common.js');

const bench = common.createBenchmark(main, {
  n: [1],
  breakOnSigint: [0, 1],
  withSigintListener: [0, 1]
});

const vm = require('vm');

function main({ n, breakOnSigint, withSigintListener }) {
  const options = breakOnSigint ? { breakOnSigint: true } : {};

  process.removeAllListeners('SIGINT');
  if (withSigintListener)
    process.on('SIGINT', () => {});

  const contextifiedSandbox = vm.createContext();

  bench.start();
  for (var i = 0; i < n; i++)
    vm.runInContext('0', contextifiedSandbox, options);
  bench.end(n);
}