39 lines
720 B
JavaScript
39 lines
720 B
JavaScript
'use strict'
|
|
|
|
const benchmark = require('benchmark')
|
|
const slow = require('./slow')
|
|
const noCollection = require('./no-collections')
|
|
const noTryCatch = require('./no-try-catch')
|
|
|
|
const suite = new benchmark.Suite()
|
|
|
|
const numbers = []
|
|
|
|
for (let i = 0; i < 1000; i++) {
|
|
numbers.push(Math.random() * i)
|
|
}
|
|
|
|
suite.add('slow', function () {
|
|
slow(12, numbers)
|
|
})
|
|
|
|
suite.add('no-collections', function () {
|
|
noCollection(12, numbers)
|
|
})
|
|
|
|
suite.add('no-try-catch', function () {
|
|
noTryCatch(12, numbers)
|
|
})
|
|
|
|
suite.on('complete', print)
|
|
|
|
suite.run()
|
|
|
|
function print () {
|
|
for (var i = 0; i < this.length; i++) {
|
|
console.log(this[i].toString())
|
|
}
|
|
|
|
console.log('Fastest is', this.filter('fastest').map('name')[0])
|
|
}
|