2022-07-28 08:09:30 +08:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
const common = require('../common.js');
|
|
|
|
|
const modPath = require.resolve('../fixtures/simple-error-stack.js');
|
2025-01-23 22:44:10 +00:00
|
|
|
const nodeModulePath = require.resolve('../fixtures/node_modules/error-stack/simple-error-stack.js');
|
|
|
|
|
const Module = require('node:module');
|
2022-07-28 08:09:30 +08:00
|
|
|
|
|
|
|
|
const bench = common.createBenchmark(main, {
|
2025-01-23 22:44:10 +00:00
|
|
|
method: [
|
|
|
|
|
'without-sourcemap',
|
|
|
|
|
'sourcemap',
|
|
|
|
|
'node-modules-without-sourcemap',
|
2025-05-04 16:55:30 -03:00
|
|
|
'node-modules-sourcemap'],
|
2022-07-28 08:09:30 +08:00
|
|
|
n: [1e5],
|
|
|
|
|
});
|
|
|
|
|
|
2025-01-23 22:44:10 +00:00
|
|
|
function runN(n, modPath) {
|
2022-07-28 08:09:30 +08:00
|
|
|
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);
|
2025-01-23 22:44:10 +00:00
|
|
|
runN(n, modPath);
|
2022-07-28 08:09:30 +08:00
|
|
|
break;
|
|
|
|
|
case 'sourcemap':
|
|
|
|
|
process.setSourceMapsEnabled(true);
|
2025-01-23 22:44:10 +00:00
|
|
|
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);
|
2022-07-28 08:09:30 +08:00
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
throw new Error(`Unexpected method "${method}"`);
|
|
|
|
|
}
|
|
|
|
|
}
|