• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2
3const common = require('../common.js');
4const modPath = require.resolve('../fixtures/simple-error-stack.js');
5
6const bench = common.createBenchmark(main, {
7  method: ['without-sourcemap', 'sourcemap'],
8  n: [1e5],
9});
10
11function runN(n) {
12  delete require.cache[modPath];
13  const mod = require(modPath);
14  bench.start();
15  for (let i = 0; i < n; i++) {
16    mod.simpleErrorStack();
17  }
18  bench.end(n);
19}
20
21function main({ n, method }) {
22  switch (method) {
23    case 'without-sourcemap':
24      process.setSourceMapsEnabled(false);
25      runN(n);
26      break;
27    case 'sourcemap':
28      process.setSourceMapsEnabled(true);
29      runN(n);
30      break;
31    default:
32      throw new Error(`Unexpected method "${method}"`);
33  }
34}
35