-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()
+ })
}
/**
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()
+)
* @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)
* @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)