-
-
Notifications
You must be signed in to change notification settings - Fork 35.5k
Expand file tree
/
Copy pathsource-text-module-chained.js
More file actions
48 lines (40 loc) · 931 Bytes
/
source-text-module-chained.js
File metadata and controls
48 lines (40 loc) · 931 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
'use strict';
const vm = require('vm');
const common = require('../common.js');
const assert = require('assert');
const bench = common.createBenchmark(main, {
stage: ['all', 'instantiate', 'evaluate'],
n: [1000],
}, {
flags: ['--experimental-vm-modules'],
});
function main({ stage, n }) {
const arr = [new vm.SourceTextModule(`
export const value = 42;
`)];
if (stage === 'all') {
bench.start();
}
for (let i = 0; i < n; i++) {
const m = new vm.SourceTextModule(`
export { value } from 'mod${i}';
`);
arr.push(m);
m.linkRequests([arr[i]]);
}
if (stage === 'instantiate') {
bench.start();
}
arr[n].instantiate();
if (stage === 'instantiate') {
bench.end(n);
}
if (stage === 'evaluate') {
bench.start();
}
arr[n].evaluate();
if (stage === 'evaluate' || stage === 'all') {
bench.end(n);
}
assert.strictEqual(arr[n].namespace.value, 42);
}