From: Jérôme Benoit Date: Mon, 24 Oct 2022 16:10:13 +0000 (+0200) Subject: Convert more benchmark to benny X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=7e8612886ac3d42901e452b0bd36781410f37b58;p=benchmarks-js.git Convert more benchmark to benny Signed-off-by: Jérôme Benoit --- diff --git a/promise-handling.js b/promise-handling.js index e4e712b..002be6d 100644 --- a/promise-handling.js +++ b/promise-handling.js @@ -1,13 +1,12 @@ -const Benchmark = require('benchmark') -const { LIST_FORMATTER } = require('./benchmark-utils') - -const suite = new Benchmark.Suite() +const Benchmark = require('benny') /** * */ function promise () { - return new Promise() + return new Promise(resolve => { + resolve() + }) } /** @@ -17,21 +16,29 @@ async function asyncFunction () { await promise() } -suite - .add('await promise', async () => { +Benchmark.suite( + 'Promise handling', + Benchmark.add('await promise', async () => { await asyncFunction() - }) - .add('promise', () => { + }), + Benchmark.add('promise', () => { asyncFunction() + }), + Benchmark.cycle(), + Benchmark.complete(), + Benchmark.save({ + file: 'promise-handling', + format: 'json', + details: true + }), + Benchmark.save({ + file: 'promise-handling', + format: 'chart.html', + details: true + }), + Benchmark.save({ + file: 'promise-handling', + format: 'table.html', + details: true }) - .on('cycle', event => { - console.log(event.target.toString()) - }) - .on('complete', function () { - console.log( - 'Fastest is ' + LIST_FORMATTER.format(this.filter('fastest').map('name')) - ) - // eslint-disable-next-line n/no-process-exit - process.exit() - }) - .run() +) diff --git a/random.js b/random.js index ee5cc61..f4fd9f0 100644 --- a/random.js +++ b/random.js @@ -9,6 +9,9 @@ const maximum = Number.MAX_SAFE_INTEGER * @returns */ function getSecureRandomInteger (max = Number.MAX_SAFE_INTEGER, min = 0) { + if (max < min || max < 0 || min < 0) { + throw new RangeError('Invalid interval') + } max = Math.floor(max) if (min != null && min !== 0) { min = Math.ceil(min) @@ -23,6 +26,9 @@ function getSecureRandomInteger (max = Number.MAX_SAFE_INTEGER, min = 0) { * @returns */ function getRandomInteger (max = Number.MAX_SAFE_INTEGER, min = 0) { + if (max < min || max < 0 || min < 0) { + throw new RangeError('Invalid interval') + } max = Math.floor(max) if (min != null && min !== 0) { min = Math.ceil(min)