11cb0ef41Sopenharmony_ci// Tests the impact on eager operations required for policies affecting
21cb0ef41Sopenharmony_ci// general startup, does not test lazy operations
31cb0ef41Sopenharmony_ci'use strict';
41cb0ef41Sopenharmony_ciconst fs = require('node:fs');
51cb0ef41Sopenharmony_ciconst path = require('node:path');
61cb0ef41Sopenharmony_ciconst common = require('../common.js');
71cb0ef41Sopenharmony_ci
81cb0ef41Sopenharmony_ciconst tmpdir = require('../../test/common/tmpdir.js');
91cb0ef41Sopenharmony_ciconst { pathToFileURL } = require('node:url');
101cb0ef41Sopenharmony_ci
111cb0ef41Sopenharmony_ciconst benchmarkDirectory =
121cb0ef41Sopenharmony_ci  path.resolve(tmpdir.path, 'benchmark-import-meta-resolve');
131cb0ef41Sopenharmony_ci
141cb0ef41Sopenharmony_ciconst parentURL = pathToFileURL(path.join(benchmarkDirectory, 'entry-point.js'));
151cb0ef41Sopenharmony_ci
161cb0ef41Sopenharmony_ciconst configs = {
171cb0ef41Sopenharmony_ci  n: [1e3],
181cb0ef41Sopenharmony_ci  specifier: [
191cb0ef41Sopenharmony_ci    './relative-existing.js',
201cb0ef41Sopenharmony_ci    './relative-nonexistent.js',
211cb0ef41Sopenharmony_ci    'unprefixed-existing',
221cb0ef41Sopenharmony_ci    'unprefixed-nonexistent',
231cb0ef41Sopenharmony_ci    'node:prefixed-nonexistent',
241cb0ef41Sopenharmony_ci    'node:os',
251cb0ef41Sopenharmony_ci  ],
261cb0ef41Sopenharmony_ci};
271cb0ef41Sopenharmony_ci
281cb0ef41Sopenharmony_ciconst options = {
291cb0ef41Sopenharmony_ci  flags: ['--expose-internals'],
301cb0ef41Sopenharmony_ci};
311cb0ef41Sopenharmony_ci
321cb0ef41Sopenharmony_ciconst bench = common.createBenchmark(main, configs, options);
331cb0ef41Sopenharmony_ci
341cb0ef41Sopenharmony_cifunction main(conf) {
351cb0ef41Sopenharmony_ci  const { defaultResolve } = require('internal/modules/esm/resolve');
361cb0ef41Sopenharmony_ci  tmpdir.refresh();
371cb0ef41Sopenharmony_ci
381cb0ef41Sopenharmony_ci  fs.mkdirSync(path.join(benchmarkDirectory, 'node_modules', 'unprefixed-existing'), { recursive: true });
391cb0ef41Sopenharmony_ci  fs.writeFileSync(path.join(benchmarkDirectory, 'node_modules', 'unprefixed-existing', 'index.js'), '\n');
401cb0ef41Sopenharmony_ci  fs.writeFileSync(path.join(benchmarkDirectory, 'relative-existing.js'), '\n');
411cb0ef41Sopenharmony_ci
421cb0ef41Sopenharmony_ci  bench.start();
431cb0ef41Sopenharmony_ci
441cb0ef41Sopenharmony_ci  for (let i = 0; i < conf.n; i++) {
451cb0ef41Sopenharmony_ci    try {
461cb0ef41Sopenharmony_ci      defaultResolve(conf.specifier, { parentURL });
471cb0ef41Sopenharmony_ci    } catch { /* empty */ }
481cb0ef41Sopenharmony_ci  }
491cb0ef41Sopenharmony_ci
501cb0ef41Sopenharmony_ci  bench.end(conf.n);
511cb0ef41Sopenharmony_ci}
52