1 import { bench, group, run } from 'tatami-ng'
3 import { generateRandomNumberArray } from './benchmark-utils.mjs'
6 const testArray = generateRandomNumberArray(size)
13 function loopMin (values) {
14 let minimum = Number.POSITIVE_INFINITY
15 for (const value of values) {
16 if (value < minimum) minimum = value
26 function reduceTernaryMin (values) {
28 (minimum, num) => (minimum < num ? minimum : num),
29 Number.POSITIVE_INFINITY
38 function reduceMathMin (values) {
40 (minimum, num) => Math.min(minimum, num),
41 Number.POSITIVE_INFINITY
50 function sortMin (values) {
51 return values.sort((a, b) => a - b)[0]
54 group(`Min from ${size} numbers`, () => {
55 bench('Math.min', () => {
56 Math.min(...testArray)
58 bench('loopMin', () => {
61 bench('reduceTernaryMin', () => {
62 reduceTernaryMin(testArray)
64 bench('reduceMathMin', () => {
65 reduceMathMin(testArray)
67 bench('sortMin', () => {