Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit e600711

Browse filesBrowse files
joyeecheungaduh95
authored andcommitted
benchmark: add benchmark for leaf source text modules
PR-URL: #60205 Refs: #59656 Refs: #37648 Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
1 parent 47fa765 commit e600711
Copy full SHA for e600711

File tree

Expand file treeCollapse file tree

1 file changed

+84
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+84
-0
lines changed
Open diff view settings
Collapse file
+84Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
'use strict';
2+
3+
const vm = require('vm');
4+
const common = require('../common.js');
5+
const assert = require('assert');
6+
7+
const bench = common.createBenchmark(main, {
8+
stage: ['all', 'compile', 'link', 'instantiate', 'evaluate'],
9+
type: ['sync', 'async'],
10+
n: [1000],
11+
}, {
12+
flags: ['--experimental-vm-modules'],
13+
});
14+
15+
function main({ stage, type, n }) {
16+
const arr = [];
17+
if (stage === 'all' || stage === 'compile') {
18+
bench.start();
19+
}
20+
21+
for (let i = 0; i < n; i++) {
22+
let source = `export const value${i} = 1;`;
23+
if (type === 'async') {
24+
source += `\nawait Promise.resolve();\n`;
25+
}
26+
const m = new vm.SourceTextModule(source);
27+
arr.push(m);
28+
}
29+
30+
if (stage === 'compile') {
31+
bench.end(n);
32+
return;
33+
}
34+
35+
if (stage === 'link') {
36+
bench.start();
37+
}
38+
39+
for (let i = 0; i < n; i++) {
40+
arr[i].linkRequests([]);
41+
}
42+
43+
if (stage === 'link') {
44+
bench.end(n);
45+
return;
46+
}
47+
48+
if (stage === 'instantiate') {
49+
bench.start();
50+
}
51+
52+
for (let i = 0; i < n; i++) {
53+
arr[i].instantiate();
54+
}
55+
56+
if (stage === 'instantiate') {
57+
bench.end(n);
58+
return;
59+
}
60+
61+
if (stage === 'evaluate') {
62+
bench.start();
63+
}
64+
65+
function finalize() {
66+
bench.end(n);
67+
for (let i = 0; i < n; i++) {
68+
assert.strictEqual(arr[i].namespace[`value${i}`], 1);
69+
}
70+
}
71+
72+
if (type === 'sync') {
73+
for (let i = 0; i < n; i++) {
74+
arr[i].evaluate();
75+
}
76+
finalize();
77+
} else {
78+
const promises = [];
79+
for (let i = 0; i < n; i++) {
80+
promises.push(arr[i].evaluate());
81+
}
82+
Promise.all(promises).then(finalize);
83+
}
84+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.