build(deps-dev): apply updates
[benchmarks-js.git] / max.mjs
diff --git a/max.mjs b/max.mjs
index 8f1f698a6a8b5f11488444913b70e17b4c11005d..23fcfdfb8762f65f91ef23d2a6cf3a9af21693fa 100644 (file)
--- a/max.mjs
+++ b/max.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,11 +11,11 @@ const testArray = generateRandomNumberArray(size)
  * @returns
  */
 function loopMax (values) {
-  let max = -Infinity
+  let maximum = -Infinity
   for (const value of values) {
-    if (value > max) max = value
+    if (value > maximum) maximum = value
   }
-  return max
+  return maximum
 }
 
 /**
@@ -23,7 +24,10 @@ function loopMax (values) {
  * @returns
  */
 function reduceTernaryMax (values) {
-  return values.reduce((a, b) => (a > b ? a : b), -Infinity)
+  return values.reduce(
+    (maximum, num) => (maximum > num ? maximum : num),
+    -Infinity
+  )
 }
 
 /**
@@ -32,7 +36,7 @@ function reduceTernaryMax (values) {
  * @returns
  */
 function reduceMathMax (values) {
-  return values.reduce((a, b) => Math.max(a, b), -Infinity)
+  return values.reduce((maximum, num) => Math.max(maximum, num), -Infinity)
 }
 
 /**
@@ -44,28 +48,24 @@ function sortMax (values) {
   return values.sort((a, b) => b - a)[0]
 }
 
-Benchmark.suite(
-  `Max from ${size} numbers`,
-  Benchmark.add('Math.max', () => {
+group(`Max from ${size} numbers`, () => {
+  bench('Math.max', () => {
     Math.max(...testArray)
-  }),
-  Benchmark.add('loopMax', () => {
+  })
+  bench('loopMax', () => {
     loopMax(testArray)
-  }),
-  Benchmark.add('reduceTernaryMax', () => {
+  })
+  bench('reduceTernaryMax', () => {
     reduceTernaryMax(testArray)
-  }),
-  Benchmark.add('reduceMath.max', () => {
+  })
+  bench('reduceMathMax', () => {
     reduceMathMax(testArray)
-  }),
-  Benchmark.add('sortMax', () => {
+  })
+  bench('sortMax', () => {
     sortMax(testArray)
-  }),
-  Benchmark.cycle(),
-  Benchmark.complete(),
-  Benchmark.save({ file: 'max', format: 'json', details: true }),
-  Benchmark.save({ file: 'max', format: 'chart.html', details: true }),
-  Benchmark.save({ file: 'max', format: 'table.html', details: true })
-).catch((err) => {
-  console.error(err)
+  })
+})
+
+await run({
+  units: true
 })