const Benchmark = require('benny')
+const { generateRandomNumberArray } = require('./benchmark-utils')
-const testArray = [
- 83, 93, 27, 29, 2828, 234, 23, 56, 32, 56, 67, 77, 32, 45, 93, 17, 28, 83, 62,
- 99, 36, 28, 93, 27, 29, 2828, 234, 23, 56, 32, 56, 67, 77, 32, 45, 93, 17, 28,
- 83, 62, 99, 36, 28, 93, 27, 29, 2828, 234, 23, 56, 32, 56, 67, 77, 32, 45, 93,
- 17, 28, 83, 62, 99, 36, 28, 93, 27, 29, 2828, 234, 23, 56, 32, 56, 67, 77, 32,
- 45, 93, 17, 28, 83, 62, 99, 36, 28, 93, 27, 29, 2828, 234, 23, 56, 32, 56, 67,
- 77, 32, 45, 93, 17, 28, 83, 62, 99, 36, 28, 93, 27, 29, 2828, 234, 23, 56, 32,
- 56, 67, 77, 32, 45, 93, 17, 28, 83, 62, 99, 36, 28, 93, 27, 29, 2828, 234, 23,
- 56, 32, 56, 67, 77, 32, 45, 93, 17, 28, 83, 62, 99, 36, 28, 93, 27, 29, 2828,
- 234, 23, 56, 32, 56, 67, 77, 32, 45, 93, 17, 28, 83, 62, 99, 36, 28, 93, 27,
- 29, 2828, 234, 23, 56, 32, 56, 67, 77, 32, 45, 93, 17, 28, 83, 62, 99, 36, 28,
- 93, 27, 29, 2828, 234, 23, 56, 32, 56, 67, 77, 32, 45, 93, 17, 28, 83, 62, 99,
- 36, 28
-]
+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 })
)