Skip to content

Commit c5d388f

Browse files
joyeecheungUlisesGascon
authored andcommitted
benchmark: rewrite import.meta benchmark
This is a ESM benchmark, rewrite it so that we are directly benchmarking the ESM import.meta paths and using number of loads for op/s calculation, instead of doing it in startup benchmarks and nesting number of process/workers spawn for op/s calculation. PR-URL: #50683 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br>
1 parent 2cf5bda commit c5d388f

File tree

4 files changed

+34
-9
lines changed

4 files changed

+34
-9
lines changed

benchmark/esm/import-meta.js

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
'use strict';
2+
3+
const path = require('path');
4+
const { pathToFileURL, fileURLToPath } = require('url');
5+
const common = require('../common');
6+
const assert = require('assert');
7+
const bench = common.createBenchmark(main, {
8+
n: [1000],
9+
});
10+
11+
const file = pathToFileURL(
12+
path.resolve(__filename, '../../fixtures/esm-dir-file.mjs'),
13+
);
14+
async function load(array, n) {
15+
for (let i = 0; i < n; i++) {
16+
array[i] = await import(`${file}?i=${i}`);
17+
}
18+
return array;
19+
}
20+
21+
function main({ n }) {
22+
const array = [];
23+
for (let i = 0; i < n; ++i) {
24+
array.push({ dirname: '', filename: '', i: 0 });
25+
}
26+
27+
bench.start();
28+
load(array, n).then((arr) => {
29+
bench.end(n);
30+
assert.strictEqual(arr[n - 1].filename, fileURLToPath(file));
31+
});
32+
}

benchmark/fixtures/esm-dir-file.mjs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
import assert from 'assert';
2-
assert.ok(import.meta.dirname);
3-
assert.ok(import.meta.filename);
1+
export const dirname = import.meta.dirname;
2+
export const filename = import.meta.filename;

benchmark/fixtures/load-esm-dir-file.js

-5
This file was deleted.

benchmark/misc/startup.js

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ const bench = common.createBenchmark(main, {
99
script: [
1010
'benchmark/fixtures/require-builtins',
1111
'test/fixtures/semicolon',
12-
'benchmark/fixtures/load-esm-dir-file',
1312
],
1413
mode: ['process', 'worker'],
1514
count: [30],

0 commit comments

Comments
 (0)