benchmark: add node-error benchmark

PR-URL: https://github.com/nodejs/node/pull/43077
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
This commit is contained in:
RafaelGSS 2022-05-12 16:19:57 -03:00
parent d72dcb0db4
commit 0903515e12
2 changed files with 35 additions and 0 deletions

14
benchmark/error/error.js Normal file
View File

@ -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);
}

View File

@ -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);
}