Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

benchmark: rewrite import.meta benchmark #50683

Merged
merged 2 commits into from Nov 18, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 29 additions & 0 deletions benchmark/esm/import-meta.js
@@ -0,0 +1,29 @@
'use strict';

const path = require('path');
const common = require('../common');
const assert = require('assert');
const bench = common.createBenchmark(main, {
n: [1000],
});

const file = path.resolve(__filename, '../../fixtures/esm-dir-file.mjs');
async function load(array, n) {
for (let i = 0; i < n; i++) {
array[i] = await import(`${file}?i=${i}`);
}
joyeecheung marked this conversation as resolved.
Show resolved Hide resolved
return array;
}

function main({ n }) {
const array = [];
for (let i = 0; i < n; ++i) {
array.push({ dirname: '', filename: '', i: 0 });
}

bench.start();
load(array, n).then((arr) => {
bench.end(n);
assert.strictEqual(arr[n - 1].filename, file);
});
}
5 changes: 2 additions & 3 deletions benchmark/fixtures/esm-dir-file.mjs
@@ -1,3 +1,2 @@
import assert from 'assert';
assert.ok(import.meta.dirname);
assert.ok(import.meta.filename);
export const dirname = import.meta.dirname;
export const filename = import.meta.filename;
5 changes: 0 additions & 5 deletions benchmark/fixtures/load-esm-dir-file.js

This file was deleted.

1 change: 0 additions & 1 deletion benchmark/misc/startup.js
Expand Up @@ -9,7 +9,6 @@ const bench = common.createBenchmark(main, {
script: [
'benchmark/fixtures/require-builtins',
'test/fixtures/semicolon',
'benchmark/fixtures/load-esm-dir-file',
],
mode: ['process', 'worker'],
count: [30],
Expand Down