GeezerVison is showing github.com — benchmark: rewrite import.meta benchmark · nodejs/node@be6ad3f
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboard +32Lines changed: 32 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
| 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 | +} |
Collapse file
Copy file name to clipboard +2-3Lines changed: 2 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
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; |
Collapse file
Copy file name to clipboardExpand all lines: benchmark/fixtures/load-esm-dir-file.js -5Lines changed: 0 additions & 5 deletions Collapse file
Copy file name to clipboardExpand all lines: benchmark/misc/startup.js -1Lines changed: 0 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -9,7 +9,6 @@ const bench = common.createBenchmark(main, { |
9 | 9 | script: [ |
10 | 10 | 'benchmark/fixtures/require-builtins', |
11 | 11 | 'test/fixtures/semicolon', |
12 | | - 'benchmark/fixtures/load-esm-dir-file', |
13 | 12 | ], |
14 | 13 | mode: ['process', 'worker'], |
15 | 14 | count: [30], |
|