Skip to content

Commit 500dee7

Browse files
committed
benchmark: rewrite import.meta benchmark
This is a ESM benchmark, rewrite it so that we are directly benchmarking the ESM import.meta paths instead of doing it in startup benchmarks which are about process/worker startup.
1 parent 5c500b7 commit 500dee7

File tree

4 files changed

+31
-9
lines changed

4 files changed

+31
-9
lines changed

β€Žbenchmark/esm/import-meta.jsβ€Ž

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

Lines changed: 0 additions & 5 deletions
This file was deleted.

β€Žbenchmark/misc/startup.jsβ€Ž

Lines changed: 0 additions & 1 deletion
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)