X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;ds=sidebyside;f=benchmarks%2Finternal%2Fbenchmark-utils.js;h=7cb4e54f500283d5c5da6e69b743f5b851ba344e;hb=3f7eb773a2c8775fa263b696b6a611e484e437a8;hp=a915a044211fa7c8c14f98c369e82c30739c1733;hpb=c2d7d79b9cfd660c1570c4ca1e056d39c5e91554;p=poolifier.git diff --git a/benchmarks/internal/benchmark-utils.js b/benchmarks/internal/benchmark-utils.js index a915a044..7cb4e54f 100644 --- a/benchmarks/internal/benchmark-utils.js +++ b/benchmarks/internal/benchmark-utils.js @@ -11,11 +11,23 @@ async function runPoolifierTest (pool, { tasks, workerData }) { } return null }) - .catch(err => console.error(err)) + .catch(err => { + console.error(err) + return reject(err) + }) } }) } +function jsonIntegerSerialization (n) { + for (let i = 0; i < n; i++) { + const o = { + a: i + } + JSON.stringify(o) + } +} + function generateRandomInteger (max, min = 0) { max = Math.floor(max) if (min) { @@ -25,9 +37,41 @@ function generateRandomInteger (max, min = 0) { return Math.floor(Math.random() * (max + 1)) } +/** + * Intentionally inefficient implementation. + * + * @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' }) -module.exports = { generateRandomInteger, LIST_FORMATTER, runPoolifierTest } +module.exports = { + runPoolifierTest, + jsonIntegerSerialization, + generateRandomInteger, + fibonacci, + factorial, + LIST_FORMATTER +}