diff --git a/benchmarks/warn.js b/benchmarks/warn.js new file mode 100644 index 0000000..8a191b4 --- /dev/null +++ b/benchmarks/warn.js @@ -0,0 +1,17 @@ +'use strict' + +const { Suite } = require('benchmark') +const warning = require('..')() + +warning.create('FastifyWarning', 'FST_ERROR_CODE_1', 'message') +warning.create('FastifyWarning', 'FST_ERROR_CODE_2', 'message') +warning.create('FastifyWarning', 'FST_ERROR_CODE_3', 'message') +new Suite() + .add('warn', function () { + warning.emit('FST_ERROR_CODE_1') + warning.emit('FST_ERROR_CODE_3') + }) + .on('cycle', function (event) { + console.log(String(event.target)) + }) + .run() diff --git a/index.js b/index.js index d0f0b6b..db43642 100644 --- a/index.js +++ b/index.js @@ -44,8 +44,8 @@ function build () { } function emit (code, a, b, c) { - if (codes[code] === undefined) throw new Error(`The code '${code}' does not exist`) if (emitted.get(code) === true) return + if (codes[code] === undefined) throw new Error(`The code '${code}' does not exist`) emitted.set(code, true) const warning = codes[code](a, b, c) diff --git a/package.json b/package.json index 0e922b4..b77ae24 100644 --- a/package.json +++ b/package.json @@ -31,6 +31,7 @@ }, "homepage": "https://github.com/fastify/fastify-warning#readme", "devDependencies": { + "benchmark": "^2.1.4", "jest": "^29.0.1", "standard": "^17.0.0", "tap": "^16.3.0",