Skip to content

Commit

Permalink
benchmark: add node-error benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
RafaelGSS committed May 25, 2022
1 parent 8b415e8 commit df87435
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
14 changes: 14 additions & 0 deletions benchmark/error/error.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
'use strict';

const common = require('../common.js');

const bench = common.createBenchmark(main, {
n: [1e7],
});

function main({ n }) {
bench.start();
for (let i = 0; i < n; ++i)
new Error('test');
bench.end(n);
}
21 changes: 21 additions & 0 deletions benchmark/error/node-error.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
'use strict';

const common = require('../common');

const bench = common.createBenchmark(main, {
n: [1e7],
}, {
flags: ['--expose-internals']
});

function main({ n }) {
const {
codes: {
ERR_INVALID_STATE,
}
} = require('internal/errors');
bench.start();
for (let i = 0; i < n; ++i)
new ERR_INVALID_STATE.TypeError('test');
bench.end(n);
}
7 changes: 7 additions & 0 deletions test/benchmark/test-benchmark-error.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict';

require('../common');

const runBenchmark = require('../common/benchmark');

runBenchmark('error', { NODEJS_BENCHMARK_ZERO_ALLOWED: 1 });

0 comments on commit df87435

Please sign in to comment.