|
| 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