forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherror-stack.js
More file actions
52 lines (48 loc) · 1.28 KB
/
error-stack.js
File metadata and controls
52 lines (48 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
'use strict';
const common = require('../common.js');
const modPath = require.resolve('../fixtures/simple-error-stack.js');
const nodeModulePath = require.resolve('../fixtures/node_modules/error-stack/simple-error-stack.js');
const Module = require('node:module');
const bench = common.createBenchmark(main, {
method: [
'without-sourcemap',
'sourcemap',
'node-modules-without-sourcemap',
'node-modules-sourcemap'],
n: [1e5],
});
function runN(n, modPath) {
delete require.cache[modPath];
const mod = require(modPath);
bench.start();
for (let i = 0; i < n; i++) {
mod.simpleErrorStack();
}
bench.end(n);
}
function main({ n, method }) {
switch (method) {
case 'without-sourcemap':
process.setSourceMapsEnabled(false);
runN(n, modPath);
break;
case 'sourcemap':
process.setSourceMapsEnabled(true);
runN(n, modPath);
break;
case 'node-modules-without-sourcemap':
Module.setSourceMapsSupport(true, {
nodeModules: false,
});
runN(n, nodeModulePath);
break;
case 'node-modules-sourcemap':
Module.setSourceMapsSupport(true, {
nodeModules: true,
});
runN(n, nodeModulePath);
break;
default:
throw new Error(`Unexpected method "${method}"`);
}
}