Skip to content

Commit a9b478e

Browse files
committed
benchmark: use typescript for import cjs benchmark
The original benchmark uses a not very realistic fixture (it has a huge try-catch block that would throw on the first line and then export at the end, hardly representative of real-world code). Also, it measures the entire import including evaluation, not just parsing. This updates the name to import-cjs to be more accurate, and use the typescript.js as the fixture which has been reported to be slow to import, leading users to use require() to work around the peformance impact.
1 parent 408aba6 commit a9b478e

File tree

2 files changed

+22
-39
lines changed

2 files changed

+22
-39
lines changed

benchmark/esm/cjs-parse.js

Lines changed: 0 additions & 39 deletions
This file was deleted.

benchmark/esm/import-cjs.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
'use strict';
2+
const common = require('../common.js');
3+
const assert = require('assert');
4+
const fixtures = require('../../test/common/fixtures.js');
5+
6+
const bench = common.createBenchmark(main, {
7+
n: [30],
8+
});
9+
10+
async function main({ n }) {
11+
// This fixture has 2000+ exports.
12+
const file = fixtures.fileURL('snapshot', 'typescript.js').href;
13+
14+
bench.start();
15+
let result;
16+
for (let i = 0; i < n; i++) {
17+
result = await import(`${file}?i=${i}`);
18+
}
19+
bench.end(n);
20+
const mod = require(fixtures.path('snapshot', 'typescript.js'));
21+
assert.strictEqual(mod, result.default);
22+
}

0 commit comments

Comments
 (0)