1 import Benchmark from 'benny'
2 import { generateRandomNumberArray } from './benchmark-utils.mjs'
5 const testArray = generateRandomNumberArray(size)
12 function loopMin (values) {
14 for (const value of values) {
15 if (value < min) min = value
25 function reduceTernaryMin (values) {
26 return values.reduce((a, b) => (a < b ? a : b), Infinity)
34 function reduceMathMin (values) {
35 return values.reduce((a, b) => Math.min(a, b), Infinity)
43 function sortMin (values) {
44 return values.sort((a, b) => a - b)[0]
48 `Min from ${size} numbers`,
49 Benchmark.add('Math.min', () => {
50 Math.min(...testArray)
52 Benchmark.add('loopMin', () => {
55 Benchmark.add('reduceTernaryMin', () => {
56 reduceTernaryMin(testArray)
58 Benchmark.add('reduceMath.min', () => {
59 reduceMathMin(testArray)
61 Benchmark.add('sortMin', () => {
66 Benchmark.save({ file: 'min', format: 'json', details: true }),
67 Benchmark.save({ file: 'min', format: 'chart.html', details: true }),
68 Benchmark.save({ file: 'min', format: 'table.html', details: true })