1 const { WorkerFunctions
} = require('./benchmarks-types')
3 async
function runPoolifierTest (pool
, { tasks
, workerData
}) {
4 return new Promise((resolve
, reject
) => {
6 for (let i
= 1; i
<= tasks
; i
++) {
11 if (executions
=== tasks
) {
12 return resolve({ ok
: 1 })
24 function jsonIntegerSerialization (n
) {
25 for (let i
= 0; i
< n
; i
++) {
33 function generateRandomInteger (max
= Number
.MAX_SAFE_INTEGER
, min
= 0) {
35 throw new RangeError('Invalid interval')
38 if (min
!= null && min
!== 0) {
39 if (max
< min
|| min
< 0) {
40 throw new RangeError('Invalid interval')
43 return Math
.floor(Math
.random() * (max
- min
+ 1)) + min
45 return Math
.floor(Math
.random() * (max
+ 1))
49 * Intentionally inefficient implementation.
51 * @param {number} n - The number of fibonacci numbers to generate.
52 * @returns {number} - The nth fibonacci number.
54 function fibonacci (n
) {
56 return fibonacci(n
- 1) + fibonacci(n
- 2)
60 * Intentionally inefficient implementation.
62 * @param {number} n - The number to calculate the factorial of.
63 * @returns {number} - The factorial of n.
65 function factorial (n
) {
69 return factorial(n
- 1) * n
73 function executeWorkerFunction (data
) {
74 switch (data
.function) {
75 case WorkerFunctions
.jsonIntegerSerialization
:
76 return jsonIntegerSerialization(data
.taskSize
|| 1000)
77 case WorkerFunctions
.fibonacci
:
78 return fibonacci(data
.taskSize
|| 1000)
79 case WorkerFunctions
.factorial
:
80 return factorial(data
.taskSize
|| 1000)
82 throw new Error('Unknown worker function')
88 executeWorkerFunction
,
89 generateRandomInteger
,