X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=benchmarks%2Finternal%2Fbenchmark-utils.js;h=7cb4e54f500283d5c5da6e69b743f5b851ba344e;hb=3f7eb773a2c8775fa263b696b6a611e484e437a8;hp=debe0b1cea518fd43a53295322a314e6736c5999;hpb=bdaf31cd0e637aa466c78d54a49f157899a2cb3f;p=poolifier.git diff --git a/benchmarks/internal/benchmark-utils.js b/benchmarks/internal/benchmark-utils.js index debe0b1c..7cb4e54f 100644 --- a/benchmarks/internal/benchmark-utils.js +++ b/benchmarks/internal/benchmark-utils.js @@ -11,7 +11,10 @@ async function runPoolifierTest (pool, { tasks, workerData }) { } return null }) - .catch(err => console.error(err)) + .catch(err => { + console.error(err) + return reject(err) + }) } }) } @@ -37,14 +40,28 @@ function generateRandomInteger (max, min = 0) { /** * Intentionally inefficient implementation. * - * @param {number} n - * @returns {number} + * @param {number} n - The number of fibonacci numbers to generate. + * @returns {number} - The nth fibonacci number. */ function fibonacci (n) { if (n <= 1) return 1 return fibonacci(n - 1) + fibonacci(n - 2) } +/** + * Intentionally inefficient implementation. + * + * @param {number} n - The number to calculate the factorial of. + * @returns {number} - The factorial of n. + */ +function factorial (n) { + if (n === 0) { + return 1 + } else { + return factorial(n - 1) * n + } +} + const LIST_FORMATTER = new Intl.ListFormat('en-US', { style: 'long', type: 'conjunction' @@ -55,5 +72,6 @@ module.exports = { jsonIntegerSerialization, generateRandomInteger, fibonacci, + factorial, LIST_FORMATTER }