const Benchmark = require('benny')
-const { generateRandomIntegerArray } = require('./benchmark-utils')
+const { generateRandomNumberArray } = require('./benchmark-utils')
-const testArray = generateRandomIntegerArray(10000)
+const size = 10000
+const testArray = generateRandomNumberArray(size)
/**
*
* @param values
+ * @returns
*/
function loopMax (values) {
let max = -Infinity
/**
*
* @param values
+ * @returns
*/
function reduceTernaryMax (values) {
return values.reduce((a, b) => (a > b ? a : b), -Infinity)
/**
*
* @param values
+ * @returns
*/
function reduceMathMax (values) {
return values.reduce((a, b) => Math.max(a, b), -Infinity)
/**
*
* @param values
+ * @returns
*/
function sortMax (values) {
return values.sort((a, b) => b - a)[0]
}
Benchmark.suite(
- 'max',
+ `Max from ${size} numbers`,
Benchmark.add('Math.max', () => {
Math.max(...testArray)
}),
Benchmark.add('reduceTernaryMax', () => {
reduceTernaryMax(testArray)
}),
- Benchmark.add('reduceMathMax', () => {
+ Benchmark.add('reduceMath.max', () => {
reduceMathMax(testArray)
}),
Benchmark.add('sortMax', () => {
}),
Benchmark.cycle(),
Benchmark.complete(),
- Benchmark.save({ file: 'max', format: 'chart.html' }),
- Benchmark.save({ file: 'max', format: 'table.html' })
+ Benchmark.save({ file: 'max', format: 'json', details: true }),
+ Benchmark.save({ file: 'max', format: 'chart.html', details: true }),
+ Benchmark.save({ file: 'max', format: 'table.html', details: true })
)