X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=min.mjs;h=44beb09d99571b35062c205ff1ba3ed3df512fa4;hb=30927da4cf771d66591a53defb7b0b8496526b58;hp=834076c94423f9e55e65e045d5721311272f21b8;hpb=4aa2893a787119ef9b3957e82539fee4fad4f98f;p=benchmarks-js.git diff --git a/min.mjs b/min.mjs index 834076c..44beb09 100644 --- a/min.mjs +++ b/min.mjs @@ -1,4 +1,5 @@ -import Benchmark from 'benny' +import { bench, group, run } from 'tatami-ng' + import { generateRandomNumberArray } from './benchmark-utils.mjs' const size = 10000 @@ -10,7 +11,7 @@ const testArray = generateRandomNumberArray(size) * @returns */ function loopMin (values) { - let minimum = Infinity + let minimum = Number.POSITIVE_INFINITY for (const value of values) { if (value < minimum) minimum = value } @@ -25,7 +26,7 @@ function loopMin (values) { function reduceTernaryMin (values) { return values.reduce( (minimum, num) => (minimum < num ? minimum : num), - Infinity + Number.POSITIVE_INFINITY ) } @@ -35,7 +36,10 @@ function reduceTernaryMin (values) { * @returns */ function reduceMathMin (values) { - return values.reduce((minimum, num) => Math.min(minimum, num), Infinity) + return values.reduce( + (minimum, num) => Math.min(minimum, num), + Number.POSITIVE_INFINITY + ) } /** @@ -47,26 +51,24 @@ function sortMin (values) { return values.sort((a, b) => a - b)[0] } -Benchmark.suite( - `Min from ${size} numbers`, - Benchmark.add('Math.min', () => { +group(`Min from ${size} numbers`, () => { + bench('Math.min', () => { Math.min(...testArray) - }), - Benchmark.add('loopMin', () => { + }) + bench('loopMin', () => { loopMin(testArray) - }), - Benchmark.add('reduceTernaryMin', () => { + }) + bench('reduceTernaryMin', () => { reduceTernaryMin(testArray) - }), - Benchmark.add('reduceMath.min', () => { + }) + bench('reduceMathMin', () => { reduceMathMin(testArray) - }), - Benchmark.add('sortMin', () => { + }) + bench('sortMin', () => { sortMin(testArray) - }), - Benchmark.cycle(), - Benchmark.complete(), - Benchmark.save({ file: 'min', format: 'json', details: true }), - Benchmark.save({ file: 'min', format: 'chart.html', details: true }), - Benchmark.save({ file: 'min', format: 'table.html', details: true }) -).catch(console.error) + }) +}) + +await run({ + units: true, +})