X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=benchmarks%2Fbenchmarks-utils.js;h=743936dabdbef3b1963fb63ce092b28881226d9b;hb=71002f09cd4b8ac7b8c6d5704222eb045acd1d7a;hp=50dcc40c6edaff1a45d885c7c0dd5d531efe3ae6;hpb=cdace0e5b9082804893de9501372490ee1064090;p=poolifier.git diff --git a/benchmarks/benchmarks-utils.js b/benchmarks/benchmarks-utils.js index 50dcc40c..743936da 100644 --- a/benchmarks/benchmarks-utils.js +++ b/benchmarks/benchmarks-utils.js @@ -1,15 +1,16 @@ +const crypto = require('crypto') const fs = require('fs') -const { - PoolTypes, - WorkerFunctions, - WorkerTypes -} = require('./benchmarks-types') const { DynamicClusterPool, DynamicThreadPool, FixedClusterPool, FixedThreadPool } = require('../lib') +const { + PoolTypes, + WorkerFunctions, + WorkerTypes +} = require('./benchmarks-types') async function runTest (pool, { taskExecutions, workerData }) { return new Promise((resolve, reject) => { @@ -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) {