X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=benchmarks%2Finternal%2Fbenchmark-utils.js;h=debe0b1cea518fd43a53295322a314e6736c5999;hb=d94bee6fb7e3c48b2490cc4fdd1fe2c205c33f2a;hp=cbf69307cdad7e5b07f5b8998099700ffafba2f7;hpb=74750c7f0a8b83b3a579f4d7fc96070ca540b234;p=poolifier.git diff --git a/benchmarks/internal/benchmark-utils.js b/benchmarks/internal/benchmark-utils.js index cbf69307..debe0b1c 100644 --- a/benchmarks/internal/benchmark-utils.js +++ b/benchmarks/internal/benchmark-utils.js @@ -1,7 +1,7 @@ async function runPoolifierTest (pool, { tasks, workerData }) { return new Promise((resolve, reject) => { let executions = 0 - for (let i = 0; i <= tasks; i++) { + for (let i = 1; i <= tasks; i++) { pool .execute(workerData) .then(res => { @@ -16,11 +16,44 @@ async function runPoolifierTest (pool, { tasks, workerData }) { }) } +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) { - return Math.floor(Math.random() * (max - min + 1) + min) + min = Math.ceil(min) + return Math.floor(Math.random() * (max - min + 1)) + min } - return Math.floor(Math.random() * max + 1) + return Math.floor(Math.random() * (max + 1)) } -module.exports = { runPoolifierTest, generateRandomInteger } +/** + * Intentionally inefficient implementation. + * + * @param {number} n + * @returns {number} + */ +function fibonacci (n) { + if (n <= 1) return 1 + return fibonacci(n - 1) + fibonacci(n - 2) +} + +const LIST_FORMATTER = new Intl.ListFormat('en-US', { + style: 'long', + type: 'conjunction' +}) + +module.exports = { + runPoolifierTest, + jsonIntegerSerialization, + generateRandomInteger, + fibonacci, + LIST_FORMATTER +}