X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=max.js;h=be3f7819314f12757d34e124b445d4941a85a114;hb=fa278e6f3d59df83bd6f422f3ee10a2b96b0b7b9;hp=5525c9293451fd335924e88a15698b43cf2e31ae;hpb=ed40d2b012a740d121f1951b9be91df341d6eaf3;p=benchmarks-js.git diff --git a/max.js b/max.js index 5525c92..be3f781 100644 --- a/max.js +++ b/max.js @@ -1,11 +1,13 @@ 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 @@ -18,6 +20,7 @@ function loopMax (values) { /** * * @param values + * @returns */ function reduceTernaryMax (values) { return values.reduce((a, b) => (a > b ? a : b), -Infinity) @@ -26,6 +29,7 @@ function reduceTernaryMax (values) { /** * * @param values + * @returns */ function reduceMathMax (values) { return values.reduce((a, b) => Math.max(a, b), -Infinity) @@ -34,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) }), @@ -50,7 +55,7 @@ Benchmark.suite( Benchmark.add('reduceTernaryMax', () => { reduceTernaryMax(testArray) }), - Benchmark.add('reduceMathMax', () => { + Benchmark.add('reduceMath.max', () => { reduceMathMax(testArray) }), Benchmark.add('sortMax', () => { @@ -58,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 }) )