Skip to content

Commit df87435

Browse files
committed
benchmark: add node-error benchmark
1 parent 8b415e8 commit df87435

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

benchmark/error/error.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
'use strict';
2+
3+
const common = require('../common.js');
4+
5+
const bench = common.createBenchmark(main, {
6+
n: [1e7],
7+
});
8+
9+
function main({ n }) {
10+
bench.start();
11+
for (let i = 0; i < n; ++i)
12+
new Error('test');
13+
bench.end(n);
14+
}

benchmark/error/node-error.js

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
5+
const bench = common.createBenchmark(main, {
6+
n: [1e7],
7+
}, {
8+
flags: ['--expose-internals']
9+
});
10+
11+
function main({ n }) {
12+
const {
13+
codes: {
14+
ERR_INVALID_STATE,
15+
}
16+
} = require('internal/errors');
17+
bench.start();
18+
for (let i = 0; i < n; ++i)
19+
new ERR_INVALID_STATE.TypeError('test');
20+
bench.end(n);
21+
}
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
'use strict';
2+
3+
require('../common');
4+
5+
const runBenchmark = require('../common/benchmark');
6+
7+
runBenchmark('error', { NODEJS_BENCHMARK_ZERO_ALLOWED: 1 });

0 commit comments

Comments
 (0)