Fix random integer gemerator
[poolifier.git] / benchmarks / internal / benchmark-utils.js
1 async function runPoolifierTest (pool, { tasks, workerData }) {
2 return new Promise((resolve, reject) => {
3 let executions = 0
4 for (let i = 1; i <= tasks; i++) {
5 pool
6 .execute(workerData)
7 .then(res => {
8 executions++
9 if (executions === tasks) {
10 return resolve('FINISH')
11 }
12 return null
13 })
14 .catch(err => console.error(err))
15 }
16 })
17 }
18
19 function generateRandomInteger (max, min = 0) {
20 if (min) {
21 return Math.floor(Math.random() * (max - min + 1)) + min
22 }
23 return Math.floor(Math.random() * (max + 1))
24 }
25
26 const LIST_FORMATTER = new Intl.ListFormat('en-US', {
27 style: 'long',
28 type: 'conjunction'
29 })
30
31 module.exports = { generateRandomInteger, LIST_FORMATTER, runPoolifierTest }