mirror of
https://github.com/nodejs/node.git
synced 2024-11-22 07:37:56 +01:00
eeddbfae6c
PR-URL: https://github.com/nodejs/node/pull/49138 Refs: https://github.com/nodejs/node/pull/49040 Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
44 lines
1.0 KiB
JavaScript
44 lines
1.0 KiB
JavaScript
// 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 common = require('../common.js');
|
|
|
|
const tmpdir = require('../../test/common/tmpdir.js');
|
|
|
|
const benchmarkDirectory = tmpdir.fileURL('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);
|
|
}
|