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