X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=max.js;h=5a486473e9d6fa3afa4aa7da9347ce6384a28e49;hb=52d07fb863422041a24874efb893c711bf0b9cd4;hp=bfa521cce36722fc35f72dc991d48fd9413b2e4a;hpb=feb629fe63173338456067e55db0aca40c4fdf4f;p=benchmarks-js.git diff --git a/max.js b/max.js index bfa521c..5a48647 100644 --- a/max.js +++ b/max.js @@ -1,11 +1,13 @@ const Benchmark = require('benny') const { generateRandomNumberArray } = require('./benchmark-utils') -const testArray = generateRandomNumberArray(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) }), @@ -61,4 +66,6 @@ Benchmark.suite( 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 }) -) +).catch(err => { + console.error(err) +})