forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathesm-loader-import.js
More file actions
45 lines (35 loc) · 1.12 KB
/
esm-loader-import.js
File metadata and controls
45 lines (35 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Tests the impact on eager operations required for policies affecting
// general startup, does not test lazy operations
'use strict';
const fs = require('node:fs');
const path = require('node:path');
const common = require('../common.js');
const tmpdir = require('../../test/common/tmpdir.js');
const { pathToFileURL } = require('node:url');
const benchmarkDirectory = pathToFileURL(path.resolve(tmpdir.path, 'benchmark-import'));
const configs = {
n: [1e3],
specifier: [
'data:text/javascript,{i}',
'./relative-existing.js',
'./relative-nonexistent.js',
'node:prefixed-nonexistent',
'node:os',
],
};
const options = {
flags: ['--expose-internals'],
};
const bench = common.createBenchmark(main, configs, options);
async function main(conf) {
tmpdir.refresh();
fs.mkdirSync(benchmarkDirectory, { recursive: true });
fs.writeFileSync(new URL('./relative-existing.js', benchmarkDirectory), '\n');
bench.start();
for (let i = 0; i < conf.n; i++) {
try {
await import(new URL(conf.specifier.replace('{i}', i), benchmarkDirectory));
} catch { /* empty */ }
}
bench.end(conf.n);
}