Repository: nodejs/node
Pull request: benchmark: disambiguate `filename` and `dirname` read perf

Extracted from https://github.com/nodejs/node/pull/57286. Can be useful to measure them separately to get more fine-grained results when working on lazyloading them.
<!--
Before submitting a pull request, please read:

- the CONTRIBUTING guide at https://github.com/nodejs/node/blob/HEAD/CONTRIBUTING.md
- the commit message formatting guidelines at
  https://github.com/nodejs/node/blob/HEAD/doc/contributing/pull-requests.md#commit-message-guidelines

For code changes:
1. Include tests for any bug fixes or new features.
2. Update documentation if relevant.
3. Ensure that `make -j4 test` (UNIX), or `vcbuild test` (Windows) passes.

If you believe this PR should be highlighted in the Node.js CHANGELOG
please add the `notable-change` label.

Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I
    have the right to submit it under the open source license
    indicated in the file; or

(b) The contribution is based upon previous work that, to the best
    of my knowledge, is covered under an appropriate open source
    license and I have the right under that license to submit that
    work with modifications, whether created in whole or in part
    by me, under the same open source license (unless I am
    permitted to submit under a different license), as indicated
    in the file; or

(c) The contribution was provided directly to me by some other
    person who certified (a), (b) or (c) and I have not modified
    it.

(d) I understand and agree that this project and the contribution
    are public and that a record of the contribution (including all
    personal information I submit with it, including my sign-off) is
    maintained indefinitely and may be redistributed consistent with
    this project or the open source license(s) involved.
-->


Changed files:
filename: benchmark/esm/import-meta.js
patch: @@ -1,32 +1,37 @@
 'use strict';
 
 const path = require('path');
-const { pathToFileURL, fileURLToPath } = require('url');
+const { pathToFileURL } = require('url');
 const common = require('../common');
 const assert = require('assert');
 const bench = common.createBenchmark(main, {
   n: [1000],
+  valuesToRead: [
+    'dirname-and-filename',
+    'dirname',
+    'filename',
+  ],
 });
 
-const file = pathToFileURL(
-  path.resolve(__filename, '../../fixtures/esm-dir-file.mjs'),
-);
-async function load(array, n) {
+const fixtureDir = path.resolve(__filename, '../../fixtures');
+const fixtureDirURL = pathToFileURL(fixtureDir);
+async function load(array, n, valuesToRead) {
   for (let i = 0; i < n; i++) {
-    array[i] = await import(`${file}?i=${i}`);
+    array[i] = await import(`${fixtureDirURL}/import-meta-${valuesToRead}.mjs?i=${i}`);
   }
   return array;
 }
 
-function main({ n }) {
+function main({ n, valuesToRead }) {
   const array = [];
   for (let i = 0; i < n; ++i) {
     array.push({ dirname: '', filename: '', i: 0 });
   }
 
   bench.start();
-  load(array, n).then((arr) => {
+  load(array, n, valuesToRead).then((arr) => {
     bench.end(n);
-    assert.strictEqual(arr[n - 1].filename, fileURLToPath(file));
+    if (valuesToRead.includes('dirname')) assert.strictEqual(arr[n - 1].dirname, fixtureDir);
+    if (valuesToRead.includes('filename')) assert.strictEqual(arr[n - 1].filename, path.join(fixtureDir, `import-meta-${valuesToRead}.mjs`));
   });
 }

filename: benchmark/fixtures/import-meta-dirname.mjs
patch: @@ -0,0 +1 @@
+export const dirname = import.meta.dirname;

filename: benchmark/fixtures/import-meta-filename.mjs
patch: @@ -0,0 +1 @@
+export const filename = import.meta.filename;