diff options
author | Ruben Bridgewater <ruben@bridgewater.de> | 2023-02-09 22:07:11 +0100 |
---|---|---|
committer | Antoine du Hamel <duhamelantoine1995@gmail.com> | 2023-02-20 15:46:55 +0100 |
commit | 841279d79c1b03fef4b864ee6681716220fa93b2 (patch) | |
tree | 0eceb4581212293cd365606e4cdc524587ac7119 /benchmark/assert/throws.js | |
parent | 1d5058d4bb23897e933aad021e30854e111aff5b (diff) | |
download | node-new-841279d79c1b03fef4b864ee6681716220fa93b2.tar.gz |
benchmark: rework assert benchmarks for correctness
This reworks most assert benchmarks to provide more reliable test
cases that also test more cases than before while keeping the
runtime low.
Signed-off-by: Ruben Bridgewater <ruben@bridgewater.de>
PR-URL: https://github.com/nodejs/node/pull/46593
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Diffstat (limited to 'benchmark/assert/throws.js')
-rw-r--r-- | benchmark/assert/throws.js | 42 |
1 files changed, 0 insertions, 42 deletions
diff --git a/benchmark/assert/throws.js b/benchmark/assert/throws.js deleted file mode 100644 index 978ad2f1b8..0000000000 --- a/benchmark/assert/throws.js +++ /dev/null @@ -1,42 +0,0 @@ -'use strict'; - -const common = require('../common.js'); -const { throws, doesNotThrow } = require('assert'); - -const bench = common.createBenchmark(main, { - n: [1e4], - method: [ 'doesNotThrow', 'throws_TypeError', 'throws_RegExp' ], -}); - -function main({ n, method }) { - const throwError = () => { throw new TypeError('foobar'); }; - const doNotThrowError = () => { return 'foobar'; }; - const regExp = /foobar/; - const message = 'failure'; - - switch (method) { - case 'doesNotThrow': - bench.start(); - for (let i = 0; i < n; ++i) { - doesNotThrow(doNotThrowError); - } - bench.end(n); - break; - case 'throws_TypeError': - bench.start(); - for (let i = 0; i < n; ++i) { - throws(throwError, TypeError, message); - } - bench.end(n); - break; - case 'throws_RegExp': - bench.start(); - for (let i = 0; i < n; ++i) { - throws(throwError, regExp, message); - } - bench.end(n); - break; - default: - throw new Error(`Unsupported method ${method}`); - } -} |