Skip to content

Commit c071304

Browse files
benchmark: use fixtures and avoid dead code for sourcemap
1 parent efa9c71 commit c071304

File tree

2 files changed

+13
-15
lines changed

2 files changed

+13
-15
lines changed

benchmark/source_map/source-map-cache.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ function main({ operation, n }) {
2121
Module.setSourceMapsSupport(true, {
2222
generatedCode: true,
2323
});
24-
const validFileName = fixtures.path('test-runner/source-maps/line-lengths/index.js')
24+
const validFileName = fixtures.path('test-runner/source-maps/line-lengths/index.js');
2525

2626
const fileNameKey = '/source-map/disk.js';
2727
const generatedFileName = fixtures.path(fileNameKey);

benchmark/source_map/source-map.js

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
const common = require('../common.js');
44
const assert = require('assert');
5-
const fs = require('fs');
6-
const path = require('path');
5+
const fixtures = require('../../test/common/fixtures');
76

87
const bench = common.createBenchmark(
98
main,
@@ -24,19 +23,14 @@ function main({ operation, n }) {
2423
const { SourceMap } = require('node:module');
2524

2625
const samplePayload = JSON.parse(
27-
fs.readFileSync(
28-
path.resolve(__dirname, '../../test/fixtures/source-map/no-source.js.map'),
29-
'utf8',
30-
),
26+
fixtures.readSync('source-map/no-source.js.map', 'utf8'),
3127
);
3228
const sectionedPayload = JSON.parse(
33-
fs.readFileSync(
34-
path.resolve(__dirname, '../../test/fixtures/source-map/disk-index.map'),
35-
'utf8',
36-
),
29+
fixtures.readSync('source-map/disk-index.map', 'utf8'),
3730
);
3831

3932
let sourceMap;
33+
let sourceMapMethod;
4034
switch (operation) {
4135
case 'parse':
4236
bench.start();
@@ -58,36 +52,40 @@ function main({ operation, n }) {
5852
sourceMap = new SourceMap(samplePayload);
5953
bench.start();
6054
for (let i = 0; i < n; i++) {
61-
sourceMap.findEntry(i, i);
55+
sourceMapMethod = sourceMap.findEntry(i, i);
6256
}
6357
bench.end(n);
58+
assert.ok(sourceMapMethod);
6459
break;
6560

6661
case 'findEntry-sectioned':
6762
sourceMap = new SourceMap(sectionedPayload);
6863
bench.start();
6964
for (let i = 0; i < n; i++) {
70-
sourceMap.findEntry(i, i);
65+
sourceMapMethod = sourceMap.findEntry(i, i);
7166
}
7267
bench.end(n);
68+
assert.ok(sourceMapMethod);
7369
break;
7470

7571
case 'findOrigin':
7672
sourceMap = new SourceMap(samplePayload);
7773
bench.start();
7874
for (let i = 0; i < n; i++) {
79-
sourceMap.findOrigin(i, i);
75+
sourceMapMethod = sourceMap.findOrigin(i, i);
8076
}
8177
bench.end(n);
78+
assert.ok(sourceMapMethod);
8279
break;
8380

8481
case 'findOrigin-sectioned':
8582
sourceMap = new SourceMap(sectionedPayload);
8683
bench.start();
8784
for (let i = 0; i < n; i++) {
88-
sourceMap.findOrigin(i, i);
85+
sourceMapMethod = sourceMap.findOrigin(i, i);
8986
}
9087
bench.end(n);
88+
assert.ok(sourceMapMethod);
9189
break;
9290

9391
default:

0 commit comments

Comments
 (0)