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 <rtrott@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
  • Loading branch information
joyeecheung authored and targos committed Nov 8, 2019
1 parent ddbf150 commit dcdb96c
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 dcdb96c

Please sign in to comment.