1// Tests the impact on eager operations required for policies affecting
2// general startup, does not test lazy operations
3'use strict';
4const fs = require('node:fs');
5const common = require('../common.js');
6
7const tmpdir = require('../../test/common/tmpdir.js');
8
9const benchmarkDirectory = tmpdir.fileURL('benchmark-import');
10
11const configs = {
12  n: [1e3],
13  specifier: [
14    'data:text/javascript,{i}',
15    './relative-existing.js',
16    './relative-nonexistent.js',
17    'node:prefixed-nonexistent',
18    'node:os',
19  ],
20};
21
22const options = {
23  flags: ['--expose-internals'],
24};
25
26const bench = common.createBenchmark(main, configs, options);
27
28async function main(conf) {
29  tmpdir.refresh();
30
31  fs.mkdirSync(benchmarkDirectory, { recursive: true });
32  fs.writeFileSync(new URL('./relative-existing.js', benchmarkDirectory), '\n');
33
34  bench.start();
35
36  for (let i = 0; i < conf.n; i++) {
37    try {
38      await import(new URL(conf.specifier.replace('{i}', i), benchmarkDirectory));
39    } catch { /* empty */ }
40  }
41
42  bench.end(conf.n);
43}
44