X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=max.js;h=be3f7819314f12757d34e124b445d4941a85a114;hb=483585ccf9408dd194d5798a862afb9e5b66e219;hp=d0d1381154170fa72776fa506f33def2aa075c30;hpb=8e5cf49deec2da334e41f116efbe2623ea25245a;p=benchmarks-js.git diff --git a/max.js b/max.js index d0d1381..be3f781 100644 --- a/max.js +++ b/max.js @@ -1,23 +1,13 @@ 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 @@ -30,6 +20,7 @@ function loopMax (values) { /** * * @param values + * @returns */ function reduceTernaryMax (values) { return values.reduce((a, b) => (a > b ? a : b), -Infinity) @@ -38,6 +29,7 @@ function reduceTernaryMax (values) { /** * * @param values + * @returns */ function reduceMathMax (values) { return values.reduce((a, b) => Math.max(a, b), -Infinity) @@ -46,13 +38,14 @@ function reduceMathMax (values) { /** * * @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) }), @@ -62,7 +55,7 @@ Benchmark.suite( Benchmark.add('reduceTernaryMax', () => { reduceTernaryMax(testArray) }), - Benchmark.add('reduceMathMax', () => { + Benchmark.add('reduceMath.max', () => { reduceMathMax(testArray) }), Benchmark.add('sortMax', () => { @@ -70,6 +63,7 @@ Benchmark.suite( }), 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 }) )