GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — benchmark: rewrite detect-esm-syntax benchmark · nodejs/node@a455372

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • benchmark/esm
    • detect-esm-syntax.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎benchmark/esm/detect-esm-syntax.js‎

Copy file name to clipboardExpand all lines: benchmark/esm/detect-esm-syntax.js
+16-17Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,33 @@
44
// We use the TypeScript fixture because it's a very large CommonJS file with no ESM syntax: the worst case.
55
const common = require('../common.js');
66
const tmpdir = require('../../test/common/tmpdir.js');
7-
const fixtures = require('../../test/common/fixtures.js');
8-
const scriptPath = fixtures.path('snapshot', 'typescript.js');
97
const fs = require('node:fs');
108

119
const bench = common.createBenchmark(main, {
12-
type: ['with-module-syntax-detection', 'without-module-syntax-detection'],
10+
type: ['with-package-json', 'without-package-json'],
1311
n: [1e4],
14-
}, {
15-
flags: ['--experimental-detect-module'],
1612
});
1713

18-
const benchmarkDirectory = tmpdir.fileURL('benchmark-detect-esm-syntax');
19-
const ambiguousURL = new URL('./typescript.js', benchmarkDirectory);
20-
const explicitURL = new URL('./typescript.cjs', benchmarkDirectory);
21-
2214
async function main({ n, type }) {
2315
tmpdir.refresh();
16+
fs.mkdirSync(tmpdir.resolve('bench'));
2417

25-
fs.mkdirSync(benchmarkDirectory, { recursive: true });
26-
fs.cpSync(scriptPath, ambiguousURL);
27-
fs.cpSync(scriptPath, explicitURL);
28-
29-
bench.start();
30-
18+
let loader = '';
19+
const modules = [];
3120
for (let i = 0; i < n; i++) {
32-
const url = type === 'with-module-syntax-detection' ? ambiguousURL : explicitURL;
33-
await import(url);
21+
const url = tmpdir.fileURL('bench', `mod${i}.js`);
22+
fs.writeFileSync(url, `const foo${i} = ${i};\nexport { foo${i} };\n`);
23+
loader += `import { foo${i} } from './mod${i}.js';\n`;
24+
modules.push(url);
3425
}
26+
const loaderURL = tmpdir.fileURL('bench', 'load.js');
27+
fs.writeFileSync(loaderURL, loader);
3528

29+
if (type === 'with-package-json') {
30+
fs.writeFileSync(tmpdir.resolve('bench', 'package.json'), '{ "type": "module" }');
31+
}
32+
33+
bench.start();
34+
await import(loaderURL);
3635
bench.end(n);
3736
}

0 commit comments

Comments
0 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.