2f60a8c5f3c0354a6ad1f37de987824844840301
1 const Benchmark
= require('benchmark')
2 const { LIST_FORMATTER
, secureRandom
} = require('./benchmark-utils')
4 const suite
= new Benchmark
.Suite()
13 function getSecureRandomInteger (max
, min
= 0) {
17 return Math
.floor(secureRandom() * (max
- min
+ 1)) + min
19 return Math
.floor(secureRandom() * (max
+ 1))
27 function getRandomInteger (max
, min
= 0) {
31 return Math
.floor(Math
.random() * (max
- min
+ 1)) + min
33 return Math
.floor(Math
.random() * (max
+ 1))
37 .add('Secure random integer generator', function () {
38 getSecureRandomInteger(maximum
)
40 .add('Random integer generator', function () {
41 getRandomInteger(maximum
)
43 .on('cycle', function (event
) {
44 console
.log(event
.target
.toString())
46 .on('complete', function () {
48 'Fastest is ' + LIST_FORMATTER
.format(this.filter('fastest').map('name'))
50 // eslint-disable-next-line n/no-process-exit