Skip to content

Commit dcdb96c

Browse files
joyeecheungtargos
authored andcommitted
benchmark: add benchmark for vm.createContext
PR-URL: #29845 Refs: #29842 Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
1 parent ddbf150 commit dcdb96c

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

benchmark/vm/create-context.js

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
'use strict';
2+
3+
const common = require('../common.js');
4+
5+
const bench = common.createBenchmark(main, {
6+
n: [100]
7+
});
8+
9+
const vm = require('vm');
10+
11+
const ctxFn = new vm.Script(`
12+
var b = Math.random();
13+
var c = a + b;
14+
`);
15+
16+
function main({ n }) {
17+
bench.start();
18+
let context;
19+
for (let i = 0; i < n; i++) {
20+
context = vm.createContext({ a: 'a' });
21+
}
22+
bench.end(n);
23+
ctxFn.runInContext(context);
24+
}

0 commit comments

Comments
 (0)