mirror of
https://github.com/zebrajr/node.git
synced 2026-01-15 12:15:26 +00:00
benchmark: add benchmark for vm.runIn*()
Introduce benchmarks for vm.runInContext() and vm.runInThisContext(). PR-URL: https://github.com/nodejs/node/pull/10816 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Brian White <mscdex@mscdex.net>
This commit is contained in:
committed by
James M Snell
parent
90a2bb53b0
commit
030dd14793
32
benchmark/vm/run-in-context.js
Normal file
32
benchmark/vm/run-in-context.js
Normal file
@@ -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
benchmark/vm/run-in-this-context.js
Normal file
29
benchmark/vm/run-in-this-context.js
Normal file
@@ -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);
|
||||
}
|
||||
Reference in New Issue
Block a user