Skip to content

Commit be6ad3f

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 a7d8f6b commit be6ad3f

4 files changed

Lines changed: 34 additions & 9 deletions

File tree

‎benchmark/esm/import-meta.js‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
'use strict';
2+
3+
constpath=require('path');
4+
const{ pathToFileURL, fileURLToPath }=require('url');
5+
constcommon=require('../common');
6+
constassert=require('assert');
7+
constbench=common.createBenchmark(main,{
8+
n: [1000],
9+
});
10+
11+
constfile=pathToFileURL(
12+
path.resolve(__filename,'../../fixtures/esm-dir-file.mjs'),
13+
);
14+
asyncfunctionload(array,n){
15+
for(leti=0;i<n;i++){
16+
array[i]=awaitimport(`${file}?i=${i}`);
17+
}
18+
returnarray;
19+
}
20+
21+
functionmain({ n }){
22+
constarray=[];
23+
for(leti=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+
}
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
importassertfrom'assert';
2-
assert.ok(import.meta.dirname);
3-
assert.ok(import.meta.filename);
1+
exportconstdirname=import.meta.dirname;
2+
exportconstfilename=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)