Skip to content

Commit d8233d9

Browse 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

1 file changed

Lines changed: 51 additions & 0 deletions

File tree

Lines 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+
constfs=require('node:fs');
5+
constpath=require('node:path');
6+
constcommon=require('../common.js');
7+
8+
consttmpdir=require('../../test/common/tmpdir.js');
9+
const{ pathToFileURL }=require('node:url');
10+
11+
constbenchmarkDirectory=
12+
path.resolve(tmpdir.path,'benchmark-import-meta-resolve');
13+
14+
constparentURL=pathToFileURL(path.join(benchmarkDirectory,'entry-point.js'));
15+
16+
constconfigs={
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+
constoptions={
29+
flags: ['--expose-internals'],
30+
};
31+
32+
constbench=common.createBenchmark(main,configs,options);
33+
34+
functionmain(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(leti=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)