]> Piment Noir Git Repositories - benchmarks-js.git/commitdiff
chore: silence linter
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Mon, 17 Nov 2025 17:19:07 +0000 (18:19 +0100)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Mon, 17 Nov 2025 17:19:07 +0000 (18:19 +0100)
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
benchmark-utils.mjs
busy-wait.mjs
fibonacci.mjs
max.mjs
min.mjs
quick-select.mjs
random.mjs

index 02e2a95a1dea4cac03976fc038dddae0bf3e14a7..1d622c916669a0224d4c027a7c45bbe6fbc25e1c 100644 (file)
@@ -1,10 +1,10 @@
 import { getRandomValues, randomBytes, randomInt } from 'node:crypto'
 
 /**
- *
- * @param max
- * @param min
- * @returns
+ * Generates a random floating-point number between min and max.
+ * @param {number} max - The maximum value (inclusive).
+ * @param {number} min - The minimum value (inclusive).
+ * @returns {number} A random floating-point number between min and max.
  */
 export function generateRandomFloat (max = Number.MAX_VALUE, min = 0) {
   if (max < min) {
@@ -17,11 +17,11 @@ export function generateRandomFloat (max = Number.MAX_VALUE, min = 0) {
 }
 
 /**
- *
- * @param size
- * @param max
- * @param numberGenerator
- * @returns
+ * Generates an array of random numbers.
+ * @param {number} size - The size of the array to generate.
+ * @param {number} max - The maximum value for generated numbers.
+ * @param {(max: number, min?: number) => number} numberGenerator - The function to use for generating numbers.
+ * @returns {Array<number>} An array of random numbers.
  */
 export function generateRandomNumberArray (
   size,
@@ -36,11 +36,11 @@ export function generateRandomNumberArray (
 }
 
 /**
- *
- * @param sizeMax
- * @param numberMax
- * @param numberGenerator
- * @returns
+ * Generates a random object with numeric values.
+ * @param {number} sizeMax - The maximum size of the object.
+ * @param {number} numberMax - The maximum value for generated numbers.
+ * @param {(max: number, min?: number) => number} numberGenerator - The function to use for generating numbers.
+ * @returns {object} A random object with numeric properties.
  */
 export function generateRandomObject (
   sizeMax = 500,
@@ -57,7 +57,7 @@ export function generateRandomObject (
 
 /**
  * Generate a cryptographically secure random number in the [0,1[ range
- * @returns
+ * @returns {number} A secure random number between 0 (inclusive) and 1 (exclusive).
  */
 export function secureRandom () {
   return randomBytes(4).readUInt32LE() / 0x100000000
@@ -65,15 +65,16 @@ export function secureRandom () {
 
 /**
  * Generate a cryptographically secure random number in the [0,1[ range
- * @returns
+ * @returns {number} A secure random number between 0 (inclusive) and 1 (exclusive).
  */
 export function secureRandomWithRandomValues () {
   return getRandomValues(new Uint32Array(1))[0] / 0x100000000
 }
 
 /**
- * @param ms
- * @returns
+ * Asynchronously sleep for a specified number of milliseconds.
+ * @param {number} ms - The number of milliseconds to sleep.
+ * @returns {Promise<void>} A promise that resolves after the specified delay.
  */
 export async function sleep (ms) {
   return await new Promise(resolve => setTimeout(resolve, ms))
index 3786e8cf25e9bfe0d5ee4effbf246fba585f10a1..3cbe0762ffbec24eacc9e8a79f6628a331e4c585 100644 (file)
@@ -6,8 +6,10 @@ const timeout = 2000
 const interval = 1000
 
 /**
- * @param timeoutMs
- * @param intervalMs
+ * Busy wait implementation using divide and conquer strategy with sleep intervals.
+ * @param {number} timeoutMs - The total timeout in milliseconds.
+ * @param {number} intervalMs - The interval between checks in milliseconds.
+ * @returns {Promise<void>} A promise that resolves after the timeout.
  */
 async function divideAndConquerTimeoutBusyWait (
   timeoutMs,
@@ -22,7 +24,9 @@ async function divideAndConquerTimeoutBusyWait (
 }
 
 /**
- * @param timeoutMs
+ * Dummy busy wait implementation using performance.now() in a tight loop.
+ * @param {number} timeoutMs - The timeout in milliseconds.
+ * @returns {void}
  */
 function dummyTimeoutBusyWait (timeoutMs) {
   const timeoutTimestampMs = performance.now() + timeoutMs
@@ -31,8 +35,10 @@ function dummyTimeoutBusyWait (timeoutMs) {
 }
 
 /**
- * @param timeoutMs
- * @param intervalMs
+ * Busy wait implementation using setInterval.
+ * @param {number} timeoutMs - The total timeout in milliseconds.
+ * @param {number} intervalMs - The interval between checks in milliseconds.
+ * @returns {Promise<void>} A promise that resolves after the timeout.
  */
 async function setIntervalTimeoutBusyWait (timeoutMs, intervalMs = interval) {
   await new Promise(resolve => {
@@ -49,8 +55,10 @@ async function setIntervalTimeoutBusyWait (timeoutMs, intervalMs = interval) {
 }
 
 /**
- * @param timeoutMs
- * @param intervalMs
+ * Busy wait implementation using repeated sleep calls.
+ * @param {number} timeoutMs - The total timeout in milliseconds.
+ * @param {number} intervalMs - The interval between sleep calls in milliseconds.
+ * @returns {Promise<void>} A promise that resolves after the timeout.
  */
 async function sleepTimeoutBusyWait (timeoutMs, intervalMs = interval) {
   const timeoutTimestampMs = performance.now() + timeoutMs
index 0ed51b4e8171938057d92b951d9fe7dc71546cad..c0cc843944018c4f33469b3a1d40f2e4d8ffbf1e 100644 (file)
@@ -3,8 +3,9 @@ import { bench, group, run } from 'tatami-ng'
 const number = 30
 
 /**
- * @param num
- * @returns
+ * Calculates the Fibonacci number at position num using a loop with array.
+ * @param {number} num - The position in the Fibonacci sequence.
+ * @returns {number} The Fibonacci number at the specified position.
  */
 function fibonacciLoop (num) {
   const fib = []
@@ -17,9 +18,9 @@ function fibonacciLoop (num) {
 }
 
 /**
- *
- * @param num
- * @returns
+ * Calculates the Fibonacci number at position num using a while loop.
+ * @param {number} num - The position in the Fibonacci sequence.
+ * @returns {number} The Fibonacci number at the specified position.
  */
 function fibonacciLoopWhile (num) {
   let current = 1
@@ -33,8 +34,9 @@ function fibonacciLoopWhile (num) {
 }
 
 /**
- * @param num
- * @returns
+ * Calculates the Fibonacci number at position num using recursion.
+ * @param {number} num - The position in the Fibonacci sequence.
+ * @returns {number} The Fibonacci number at the specified position.
  */
 function fibonacciRecursion (num) {
   if (num <= 1) return num
@@ -42,9 +44,10 @@ function fibonacciRecursion (num) {
 }
 
 /**
- * @param num
- * @param memo
- * @returns
+ * Calculates the Fibonacci number at position num using recursion with memoization.
+ * @param {number} num - The position in the Fibonacci sequence.
+ * @param {{[key: number]: number}} [memo] - The memoization object to cache results.
+ * @returns {number} The Fibonacci number at the specified position.
  */
 function fibonacciRecursionMemoization (num, memo) {
   memo = memo || {}
diff --git a/max.mjs b/max.mjs
index 23d856e9a2a242bad517150e935ca59df7eb07db..2b43541184100fad8ba0455f56e9726839df74b0 100644 (file)
--- a/max.mjs
+++ b/max.mjs
@@ -6,9 +6,9 @@ const size = 10000
 const testArray = generateRandomNumberArray(size)
 
 /**
- *
- * @param values
- * @returns
+ * Finds the maximum value in an array using a loop.
+ * @param {Array<number>} values - The array of numbers to search.
+ * @returns {number} The maximum value in the array.
  */
 function loopMax (values) {
   let maximum = Number.NEGATIVE_INFINITY
@@ -19,9 +19,9 @@ function loopMax (values) {
 }
 
 /**
- *
- * @param values
- * @returns
+ * Finds the maximum value in an array using reduce with Math.max.
+ * @param {Array<number>} values - The array of numbers to search.
+ * @returns {number} The maximum value in the array.
  */
 function reduceMathMax (values) {
   return values.reduce(
@@ -31,9 +31,9 @@ function reduceMathMax (values) {
 }
 
 /**
- *
- * @param values
- * @returns
+ * Finds the maximum value in an array using reduce with ternary operator.
+ * @param {Array<number>} values - The array of numbers to search.
+ * @returns {number} The maximum value in the array.
  */
 function reduceTernaryMax (values) {
   return values.reduce(
@@ -43,9 +43,9 @@ function reduceTernaryMax (values) {
 }
 
 /**
- *
- * @param values
- * @returns
+ * Finds the maximum value in an array by sorting.
+ * @param {Array<number>} values - The array of numbers to search.
+ * @returns {number} The maximum value in the array.
  */
 function sortMax (values) {
   return values.sort((a, b) => b - a)[0]
diff --git a/min.mjs b/min.mjs
index 8d259febdddcdf4d31c9661c8e711375c03b5e5e..2e5e4070067d10ab956b4ac2660b54902b04fb31 100644 (file)
--- a/min.mjs
+++ b/min.mjs
@@ -6,9 +6,9 @@ const size = 10000
 const testArray = generateRandomNumberArray(size)
 
 /**
- *
- * @param values
- * @returns
+ * Finds the minimum value in an array using a loop.
+ * @param {Array<number>} values - The array of numbers to search.
+ * @returns {number} The minimum value in the array.
  */
 function loopMin (values) {
   let minimum = Number.POSITIVE_INFINITY
@@ -19,9 +19,9 @@ function loopMin (values) {
 }
 
 /**
- *
- * @param values
- * @returns
+ * Finds the minimum value in an array using reduce with Math.min.
+ * @param {Array<number>} values - The array of numbers to search.
+ * @returns {number} The minimum value in the array.
  */
 function reduceMathMin (values) {
   return values.reduce(
@@ -31,9 +31,9 @@ function reduceMathMin (values) {
 }
 
 /**
- *
- * @param values
- * @returns
+ * Finds the minimum value in an array using reduce with ternary operator.
+ * @param {Array<number>} values - The array of numbers to search.
+ * @returns {number} The minimum value in the array.
  */
 function reduceTernaryMin (values) {
   return values.reduce(
@@ -43,9 +43,9 @@ function reduceTernaryMin (values) {
 }
 
 /**
- *
- * @param values
- * @returns
+ * Finds the minimum value in an array by sorting.
+ * @param {Array<number>} values - The array of numbers to search.
+ * @returns {number} The minimum value in the array.
  */
 function sortMin (values) {
   return values.sort((a, b) => a - b)[0]
index b158c6b741e602247665690c97cb4a10596022e2..645cad213f84d551f0a445b5f99eb75ef445ba44 100644 (file)
@@ -2,9 +2,10 @@ import { randomInt } from 'node:crypto'
 import { bench, group, run } from 'tatami-ng'
 
 /**
- * @param numberOfWorkers
- * @param maxNumberOfTasksPerWorker
- * @returns
+ * Generates a random tasks map for benchmarking.
+ * @param {number} numberOfWorkers - The number of workers.
+ * @param {number} maxNumberOfTasksPerWorker - The maximum number of tasks per worker.
+ * @returns {Map} A map with worker IDs as keys and task counts as values.
  */
 function generateRandomTasksMap (
   numberOfWorkers,
@@ -21,8 +22,9 @@ function generateRandomTasksMap (
 const tasksMap = generateRandomTasksMap(60, 20)
 
 /**
- * @param tasksMap
- * @returns
+ * Selects the task with minimum value using array sort.
+ * @param {Map} tasksMap - The map of tasks to search.
+ * @returns {Array} The task entry with the minimum value.
  */
 function arraySortSelect (tasksMap) {
   const tasksArray = Array.from(tasksMap)
@@ -37,8 +39,9 @@ function arraySortSelect (tasksMap) {
 }
 
 /**
- * @param tasksMap
- * @returns
+ * Selects the task with minimum value using a loop.
+ * @param {Map} tasksMap - The map of tasks to search.
+ * @returns {Array|number} The task entry with the minimum value.
  */
 function loopSelect (tasksMap) {
   let minKey
@@ -67,12 +70,14 @@ const randomPivotIndexSelect = (leftIndex, rightIndex) => {
 }
 
 /**
- * @param array
- * @param leftIndex
- * @param rightIndex
- * @param pivotIndex
- * @param compare
- * @returns
+ * Partitions an array for quickselect algorithm.
+ * @template T
+ * @param {Array<T>} array - The array to partition.
+ * @param {number} leftIndex - The left index of the partition range.
+ * @param {number} rightIndex - The right index of the partition range.
+ * @param {number} pivotIndex - The index of the pivot element.
+ * @param {(a: T, b: T) => boolean} compare - The comparison function.
+ * @returns {number} The final position of the pivot element.
  */
 function partition (
   array,
@@ -95,8 +100,9 @@ function partition (
 }
 
 /**
- * @param tasksMap
- * @returns
+ * Selects task using quickselect with loop implementation.
+ * @param {Map} tasksMap - The map of tasks to search.
+ * @returns {Array} The task entry with the minimum value.
  */
 function quickSelectLoop (tasksMap) {
   const tasksArray = Array.from(tasksMap)
@@ -107,8 +113,9 @@ function quickSelectLoop (tasksMap) {
 }
 
 /**
- * @param tasksMap
- * @returns
+ * Selects task using quickselect with loop and random pivot.
+ * @param {Map} tasksMap - The map of tasks to search.
+ * @returns {Array} The task entry with the minimum value.
  */
 function quickSelectLoopRandomPivot (tasksMap) {
   const tasksArray = Array.from(tasksMap)
@@ -126,8 +133,9 @@ function quickSelectLoopRandomPivot (tasksMap) {
 }
 
 /**
- * @param tasksMap
- * @returns
+ * Selects task using quickselect with recursion.
+ * @param {Map} tasksMap - The map of tasks to search.
+ * @returns {Array} The task entry with the minimum value.
  */
 function quickSelectRecursion (tasksMap) {
   const tasksArray = Array.from(tasksMap)
@@ -138,8 +146,9 @@ function quickSelectRecursion (tasksMap) {
 }
 
 /**
- * @param tasksMap
- * @returns
+ * Selects task using quickselect with recursion and random pivot.
+ * @param {Map} tasksMap - The map of tasks to search.
+ * @returns {Array} The task entry with the minimum value.
  */
 function quickSelectRecursionRandomPivot (tasksMap) {
   const tasksArray = Array.from(tasksMap)
@@ -157,13 +166,15 @@ function quickSelectRecursionRandomPivot (tasksMap) {
 }
 
 /**
- * @param array
- * @param k
- * @param leftIndex
- * @param rightIndex
- * @param compare
- * @param pivotIndexSelect
- * @returns
+ * Quickselect algorithm using loop implementation.
+ * @template T
+ * @param {Array<T>} array - The array to search.
+ * @param {number} k - The k-th element to find.
+ * @param {number} leftIndex - The left boundary index.
+ * @param {number} rightIndex - The right boundary index.
+ * @param {(a: T, b: T) => boolean} compare - The comparison function.
+ * @param {(leftIndex: number, rightIndex: number) => number} pivotIndexSelect - The pivot selection function.
+ * @returns {T} The k-th element.
  */
 function selectLoop (
   array,
@@ -188,13 +199,15 @@ function selectLoop (
 }
 
 /**
- * @param array
- * @param k
- * @param leftIndex
- * @param rightIndex
- * @param compare
- * @param pivotIndexSelect
- * @returns
+ * Quickselect algorithm using recursion.
+ * @template T
+ * @param {Array<T>} array - The array to search.
+ * @param {number} k - The k-th element to find.
+ * @param {number} leftIndex - The left boundary index.
+ * @param {number} rightIndex - The right boundary index.
+ * @param {(a: T, b: T) => boolean} compare - The comparison function.
+ * @param {(leftIndex: number, rightIndex: number) => number} pivotIndexSelect - The pivot selection function.
+ * @returns {T} The k-th element.
  */
 function selectRecursion (
   array,
@@ -217,9 +230,11 @@ function selectRecursion (
 }
 
 /**
- * @param array
- * @param index1
- * @param index2
+ * Swaps two elements in an array.
+ * @param {Array} array - The array containing elements to swap.
+ * @param {number} index1 - The index of the first element.
+ * @param {number} index2 - The index of the second element.
+ * @returns {void}
  */
 function swap (array, index1, index2) {
   const tmp = array[index1]
index 8b4b2a6c055cb133d7b2ce5c1d98e65ea862abfe..f5aac7b8edc6d3f9e0283a18d6e1f565cde61813 100644 (file)
@@ -9,9 +9,10 @@ import {
 const maximum = 281474976710655
 
 /**
- * @param max
- * @param min
- * @returns
+ * Generates a random integer between min and max using Math.random.
+ * @param {number} max - The maximum value (inclusive).
+ * @param {number} min - The minimum value (inclusive).
+ * @returns {number} A random integer between min and max.
  */
 function getRandomInteger (max = Number.MAX_SAFE_INTEGER, min = 0) {
   if (max < min || max < 0 || min < 0) {
@@ -26,9 +27,10 @@ function getRandomInteger (max = Number.MAX_SAFE_INTEGER, min = 0) {
 }
 
 /**
- * @param max
- * @param min
- * @returns
+ * Generates a cryptographically secure random integer using secureRandom.
+ * @param {number} max - The maximum value (inclusive).
+ * @param {number} min - The minimum value (inclusive).
+ * @returns {number} A secure random integer between min and max.
  */
 function getSecureRandomInteger (max = Number.MAX_SAFE_INTEGER, min = 0) {
   if (max < min || max < 0 || min < 0) {
@@ -43,9 +45,10 @@ function getSecureRandomInteger (max = Number.MAX_SAFE_INTEGER, min = 0) {
 }
 
 /**
- * @param max
- * @param min
- * @returns
+ * Generates a cryptographically secure random integer using getRandomValues.
+ * @param {number} max - The maximum value (inclusive).
+ * @param {number} min - The minimum value (inclusive).
+ * @returns {number} A secure random integer between min and max.
  */
 function getSecureRandomIntegerWithRandomValues (
   max = Number.MAX_SAFE_INTEGER,