Skip to content

Commit 030dd14

Browse files
Trottjasnell
authored andcommitted
benchmark: add benchmark for vm.runIn*()
Introduce benchmarks for vm.runInContext() and vm.runInThisContext(). PR-URL: #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]>
1 parent 90a2bb5 commit 030dd14

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

benchmark/vm/run-in-context.js

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
'use strict';
2+
3+
const common = require('../common.js');
4+
5+
const bench = common.createBenchmark(main, {
6+
n: [1],
7+
breakOnSigint: [0, 1],
8+
withSigintListener: [0, 1]
9+
});
10+
11+
const vm = require('vm');
12+
13+
function main(conf) {
14+
const n = +conf.n;
15+
const options = conf.breakOnSigint ? {breakOnSigint: true} : {};
16+
const withSigintListener = !!conf.withSigintListener;
17+
18+
process.removeAllListeners('SIGINT');
19+
if (withSigintListener)
20+
process.on('SIGINT', () => {});
21+
22+
var i = 0;
23+
24+
const contextifiedSandbox = vm.createContext();
25+
26+
common.v8ForceOptimization(vm.runInContext,
27+
'0', contextifiedSandbox, options);
28+
bench.start();
29+
for (; i < n; i++)
30+
vm.runInContext('0', contextifiedSandbox, options);
31+
bench.end(n);
32+
}

benchmark/vm/run-in-this-context.js

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
'use strict';
2+
3+
const common = require('../common.js');
4+
5+
const bench = common.createBenchmark(main, {
6+
n: [1],
7+
breakOnSigint: [0, 1],
8+
withSigintListener: [0, 1]
9+
});
10+
11+
const vm = require('vm');
12+
13+
function main(conf) {
14+
const n = +conf.n;
15+
const options = conf.breakOnSigint ? {breakOnSigint: true} : {};
16+
const withSigintListener = !!conf.withSigintListener;
17+
18+
process.removeAllListeners('SIGINT');
19+
if (withSigintListener)
20+
process.on('SIGINT', () => {});
21+
22+
var i = 0;
23+
24+
common.v8ForceOptimization(vm.runInThisContext, '0', options);
25+
bench.start();
26+
for (; i < n; i++)
27+
vm.runInThisContext('0', options);
28+
bench.end(n);
29+
}

0 commit comments

Comments
 (0)