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 = -Infinity
15 for (const value of values) {
16 if (value > maximum) maximum = value
26 function reduceTernaryMax (values) {
28 (maximum, num) => (maximum > num ? maximum : num),
38 function reduceMathMax (values) {
39 return values.reduce((maximum, num) => Math.max(maximum, num), -Infinity)
47 function sortMax (values) {
48 return values.sort((a, b) => b - a)[0]
51 group(`Max from ${size} numbers`, () => {
52 bench('Math.max', () => {
53 Math.max(...testArray)
55 bench('loopMax', () => {
58 bench('reduceTernaryMax', () => {
59 reduceTernaryMax(testArray)
61 bench('reduceMathMax', () => {
62 reduceMathMax(testArray)
64 bench('sortMax', () => {