From aefc9dda9a211402e74e7a7919708ec9c600140e Mon Sep 17 00:00:00 2001 From: RafaelGSS Date: Thu, 12 May 2022 16:19:57 -0300 Subject: [PATCH] benchmark: add node-error benchmark MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/nodejs/node/pull/43077 Reviewed-By: Matteo Collina Reviewed-By: Juan José Arboleda Reviewed-By: Antoine du Hamel --- benchmark/error/error.js | 14 ++++++++++++++ benchmark/error/node-error.js | 21 +++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 benchmark/error/error.js create mode 100644 benchmark/error/node-error.js diff --git a/benchmark/error/error.js b/benchmark/error/error.js new file mode 100644 index 00000000000000..c856f3e07f6bea --- /dev/null +++ b/benchmark/error/error.js @@ -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); +} diff --git a/benchmark/error/node-error.js b/benchmark/error/node-error.js new file mode 100644 index 00000000000000..f672522b2d0a65 --- /dev/null +++ b/benchmark/error/node-error.js @@ -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); +}