Skip to content

Commit

Permalink
benchmark: add benchmark for vm.createContext
Browse files Browse the repository at this point in the history
PR-URL: #29845
Refs: #29842
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
  • Loading branch information
joyeecheung committed Oct 10, 2019
1 parent 179f423 commit 1294c7e
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions benchmark/vm/create-context.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
'use strict';

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

const bench = common.createBenchmark(main, {
n: [100]
});

const vm = require('vm');

const ctxFn = new vm.Script(`
var b = Math.random();
var c = a + b;
`);

function main({ n }) {
bench.start();
let context;
for (let i = 0; i < n; i++) {
context = vm.createContext({ a: 'a' });
}
bench.end(n);
ctxFn.runInContext(context);
}

0 comments on commit 1294c7e

Please sign in to comment.