98b59ed34f5241db671aad996fecc51b58ecdb05
1 const Benchmark
= require('benchmark')
2 const { LIST_FORMATTER
, secureRandom
} = require('./benchmark-utils')
4 const suite
= new Benchmark
.Suite()
12 function getSecureRandomInteger (max
, min
= 0) {
16 return Math
.floor(secureRandom() * (max
- min
+ 1)) + min
18 return Math
.floor(secureRandom() * (max
+ 1))
25 function getRandomInteger (max
, min
= 0) {
29 return Math
.floor(Math
.random() * (max
- min
+ 1)) + min
31 return Math
.floor(Math
.random() * (max
+ 1))
35 .add('Secure random integer generator', function () {
36 getSecureRandomInteger(maximum
)
38 .add('Random integer generator', function () {
39 getRandomInteger(maximum
)
41 .on('cycle', function (event
) {
42 console
.log(event
.target
.toString())
44 .on('complete', function () {
46 'Fastest is ' + LIST_FORMATTER
.format(this.filter('fastest').map('name'))
48 // eslint-disable-next-line no-process-exit