mirror of
https://github.com/nodejs/node.git
synced 2025-08-15 13:48:44 +02:00
benchmark: add vm context global proxy benchmark
PR-URL: https://github.com/nodejs/node/pull/44796 Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
d5ce285c8b
commit
b3531bf735
1 changed files with 21 additions and 0 deletions
21
benchmark/vm/context-global-proxy.js
Normal file
21
benchmark/vm/context-global-proxy.js
Normal file
|
@ -0,0 +1,21 @@
|
|||
'use strict';
|
||||
|
||||
const common = require('../common.js');
|
||||
|
||||
const bench = common.createBenchmark(main, {
|
||||
n: [100000],
|
||||
});
|
||||
|
||||
const vm = require('vm');
|
||||
const script = new vm.Script(`
|
||||
globalThis.foo++;
|
||||
`);
|
||||
const context = vm.createContext({ foo: 1 });
|
||||
|
||||
function main({ n }) {
|
||||
bench.start();
|
||||
for (let i = 0; i < n; i++) {
|
||||
script.runInContext(context);
|
||||
}
|
||||
bench.end(n);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue