X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=benchmarks%2Fbenchmarks-utils.js;h=aac4b78583923252c0c8972273d7c8aced7f9842;hb=437d25258782c8801daa58829575d5a51c05dcee;hp=50dcc40c6edaff1a45d885c7c0dd5d531efe3ae6;hpb=cdace0e5b9082804893de9501372490ee1064090;p=poolifier.git diff --git a/benchmarks/benchmarks-utils.js b/benchmarks/benchmarks-utils.js index 50dcc40c..aac4b785 100644 --- a/benchmarks/benchmarks-utils.js +++ b/benchmarks/benchmarks-utils.js @@ -1,3 +1,4 @@ +const crypto = require('crypto') const fs = require('fs') const { PoolTypes, @@ -55,7 +56,6 @@ function jsonIntegerSerialization (n) { /** * Intentionally inefficient implementation. - * * @param {number} n - The number of fibonacci numbers to generate. * @returns {number} - The nth fibonacci number. */ @@ -66,7 +66,6 @@ function fibonacci (n) { /** * Intentionally inefficient implementation. - * * @param {number} n - The number to calculate the factorial of. * @returns {number} - The factorial of n. */ @@ -77,11 +76,16 @@ function factorial (n) { return factorial(n - 1) * n } -function readWriteFiles (n) { - const baseDirectory = '/tmp/poolifier-benchmarks' - if (fs.existsSync(baseDirectory) === false) { - fs.mkdirSync(baseDirectory, { recursive: true }) +function readWriteFiles ( + n, + baseDirectory = `/tmp/poolifier-benchmarks/${crypto.randomInt( + 281474976710655 + )}` +) { + if (fs.existsSync(baseDirectory) === true) { + fs.rmSync(baseDirectory, { recursive: true }) } + fs.mkdirSync(baseDirectory, { recursive: true }) for (let i = 0; i < n; i++) { const filePath = `${baseDirectory}/${i}` fs.writeFileSync(filePath, i.toString(), { @@ -90,6 +94,7 @@ function readWriteFiles (n) { }) fs.readFileSync(filePath, 'utf8') } + fs.rmSync(baseDirectory, { recursive: true }) } function executeWorkerFunction (data) { @@ -107,7 +112,7 @@ function executeWorkerFunction (data) { } } -function buildPool (poolType, poolSize, workerType, poolOptions) { +function buildPool (workerType, poolType, poolSize, poolOptions) { switch (poolType) { case PoolTypes.FIXED: switch (workerType) {