Skip to content

Commit

Permalink
benchmark: add benchmark for vm.runIn*()
Browse files Browse the repository at this point in the history
Introduce benchmarks for vm.runInContext() and vm.runInThisContext().

PR-URL: nodejs#10816
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Ben Noordhuis <[email protected]>
Reviewed-By: Brian White <[email protected]>
  • Loading branch information
Trott authored and italoacasas committed Jan 23, 2017
1 parent 714e04b commit b1e2dc7
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
32 changes: 32 additions & 0 deletions benchmark/vm/run-in-context.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
'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(conf) {
const n = +conf.n;
const options = conf.breakOnSigint ? {breakOnSigint: true} : {};
const withSigintListener = !!conf.withSigintListener;

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

var i = 0;

const contextifiedSandbox = vm.createContext();

common.v8ForceOptimization(vm.runInContext,
'0', contextifiedSandbox, options);
bench.start();
for (; i < n; i++)
vm.runInContext('0', contextifiedSandbox, options);
bench.end(n);
}
29 changes: 29 additions & 0 deletions benchmark/vm/run-in-this-context.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
'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(conf) {
const n = +conf.n;
const options = conf.breakOnSigint ? {breakOnSigint: true} : {};
const withSigintListener = !!conf.withSigintListener;

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

var i = 0;

common.v8ForceOptimization(vm.runInThisContext, '0', options);
bench.start();
for (; i < n; i++)
vm.runInThisContext('0', options);
bench.end(n);
}

0 comments on commit b1e2dc7

Please sign in to comment.