Skip to content

Commit 4147ff3

Browse files
benchmark: add performance benchmark for prepareStackTraceWithSourceMaps
1 parent 31485be commit 4147ff3

File tree

4 files changed

+65
-5
lines changed

4 files changed

+65
-5
lines changed

benchmark/es/error-stack.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const bench = common.createBenchmark(main, {
1010
'without-sourcemap',
1111
'sourcemap',
1212
'node-modules-without-sourcemap',
13-
'node-modules-sourcemap'],
13+
'node-module-sourcemap'],
1414
n: [1e5],
1515
});
1616

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
'use strict';
2+
3+
const common = require('../common.js');
4+
const kIsNodeError = Symbol('kIsNodeError');
5+
6+
const options = {
7+
flags: ['--expose-internals'],
8+
};
9+
10+
const bench = common.createBenchmark(
11+
main,
12+
{
13+
operation: ['node-error-callsite', 'non-node-error-callsite'],
14+
n: [1e5],
15+
},
16+
options,
17+
);
18+
19+
function main({ operation, n }) {
20+
const { prepareStackTraceWithSourceMaps } = require('internal/source_map/prepare_stack_trace');
21+
22+
const nodeError = new Error('Simulated Node.js error');
23+
nodeError.name = 'NodeError';
24+
nodeError.code = 'ERR_SIMULATED';
25+
nodeError[kIsNodeError] = true;
26+
27+
const nodeStackTrace = Array.from({ length: 10 }, (_, i) => ({
28+
getFileName: () => `file${i}.js`,
29+
getEvalOrigin: () => `eval at <anonymous> (eval${i}.js:1:1)`,
30+
getLineNumber: () => i + 1,
31+
getColumnNumber: () => 1,
32+
getFunctionName: () => `func${i}`,
33+
isAsync: () => false,
34+
isConstructor: () => false,
35+
getTypeName: () => null,
36+
}));
37+
38+
const nonNodeError = new Error('Simulated non-Node.js error');
39+
nonNodeError.name = 'NonNodeError';
40+
41+
switch (operation) {
42+
case 'node-error-callsite':
43+
bench.start();
44+
for (let i = 0; i < n; i++) {
45+
prepareStackTraceWithSourceMaps(nodeError, nodeStackTrace);
46+
}
47+
bench.end(n);
48+
break;
49+
50+
case 'non-node-error-callsite':
51+
bench.start();
52+
for (let i = 0; i < n; i++) {
53+
prepareStackTraceWithSourceMaps(nonNodeError, nodeStackTrace);
54+
}
55+
bench.end(n);
56+
break;
57+
58+
default:
59+
throw new Error(`Unknown operation: ${operation}`);
60+
}
61+
}

benchmark/source_map/source-map-cache.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,8 @@ function main({ operation, n }) {
5757
maybeCacheSourceMap(validFileName, validFileContent, null, false);
5858
maybeCacheSourceMap(invalidFileName, invalidFileContent, null, false);
5959
maybeCacheSourceMap(generatedSourceFileName, generatedSourceContent, null, true,
60-
`/${generatedSourceFileName}`,
61-
`${generatedSourceFileName}.map`,
62-
);
60+
`/${generatedSourceFileName}`,
61+
`${generatedSourceFileName}.map`);
6362

6463
switch (operation) {
6564
case 'findSourceMap-valid':

doc/contributing/writing-and-running-benchmarks.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ benchmarks. This increases the likelihood of each benchmark achieving peak perfo
101101
according to the hardware. Therefore, run:
102102

103103
```console
104-
$ ./benchmark/cpu.sh fast
104+
$ ./benchmarks/cpu.sh fast
105105
```
106106

107107
### Running individual benchmarks

0 commit comments

Comments
 (0)