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 d8233d9

Browse filesBrowse files
aduh95MoLow
authored andcommitted
benchmark: add a benchmark for defaultResolve
PR-URL: #47543 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com> Reviewed-By: Jacob Smith <jacob@frende.me>
1 parent c522762 commit d8233d9
Copy full SHA for d8233d9

File tree

Expand file treeCollapse file tree

1 file changed

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

1 file changed

+51
-0
lines changed
Open diff view settings
Collapse file
+51Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Tests the impact on eager operations required for policies affecting
2+
// general startup, does not test lazy operations
3+
'use strict';
4+
const fs = require('node:fs');
5+
const path = require('node:path');
6+
const common = require('../common.js');
7+
8+
const tmpdir = require('../../test/common/tmpdir.js');
9+
const { pathToFileURL } = require('node:url');
10+
11+
const benchmarkDirectory =
12+
path.resolve(tmpdir.path, 'benchmark-import-meta-resolve');
13+
14+
const parentURL = pathToFileURL(path.join(benchmarkDirectory, 'entry-point.js'));
15+
16+
const configs = {
17+
n: [1e3],
18+
specifier: [
19+
'./relative-existing.js',
20+
'./relative-nonexistent.js',
21+
'unprefixed-existing',
22+
'unprefixed-nonexistent',
23+
'node:prefixed-nonexistent',
24+
'node:os',
25+
],
26+
};
27+
28+
const options = {
29+
flags: ['--expose-internals'],
30+
};
31+
32+
const bench = common.createBenchmark(main, configs, options);
33+
34+
function main(conf) {
35+
const { defaultResolve } = require('internal/modules/esm/resolve');
36+
tmpdir.refresh();
37+
38+
fs.mkdirSync(path.join(benchmarkDirectory, 'node_modules', 'unprefixed-existing'), { recursive: true });
39+
fs.writeFileSync(path.join(benchmarkDirectory, 'node_modules', 'unprefixed-existing', 'index.js'), '\n');
40+
fs.writeFileSync(path.join(benchmarkDirectory, 'relative-existing.js'), '\n');
41+
42+
bench.start();
43+
44+
for (let i = 0; i < conf.n; i++) {
45+
try {
46+
defaultResolve(conf.specifier, { parentURL });
47+
} catch { /* empty */ }
48+
}
49+
50+
bench.end(conf.n);
51+
}

0 commit comments

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