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 <rtrott@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
1 parent ddbf150 commit dcdb96c

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

‎benchmark/vm/create-context.js‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
'use strict';
2+
3+
constcommon=require('../common.js');
4+
5+
constbench=common.createBenchmark(main,{
6+
n: [100]
7+
});
8+
9+
constvm=require('vm');
10+
11+
constctxFn=newvm.Script(`
12+
var b = Math.random();
13+
var c = a + b;
14+
`);
15+
16+
functionmain({ n }){
17+
bench.start();
18+
letcontext;
19+
for(leti=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)