Skip to content

Commit 7a0b11e

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

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
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+
const {
5+
codes: {
6+
ERR_INVALID_STATE,
7+
}
8+
} = require('internal/errors');
9+
10+
const bench = common.createBenchmark(main, {
11+
n: [1e7],
12+
}, {
13+
flags: ['--expose-internals']
14+
});
15+
16+
function main({ n }) {
17+
bench.start();
18+
for (let i = 0; i < n; ++i)
19+
new ERR_INVALID_STATE.TypeError('test');
20+
bench.end(n);
21+
}

lib/util.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ const {
4848
codes: {
4949
ERR_FALSY_VALUE_REJECTION,
5050
ERR_INVALID_ARG_TYPE,
51-
ERR_OUT_OF_RANGE
51+
ERR_OUT_OF_RANGE,
5252
},
5353
errnoException,
5454
exceptionWithHostPort,

0 commit comments

Comments
 (0)