8bd137a34e3fdbc5a8d8418ac00e097ba251f64f
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 if (min
!= null || min
!== 0) {
37 return Math
.floor(Math
.random() * (max
- min
+ 1)) + min
39 return Math
.floor(Math
.random() * (max
+ 1))
43 * Intentionally inefficient implementation.
45 * @param {number} n - The number of fibonacci numbers to generate.
46 * @returns {number} - The nth fibonacci number.
48 function fibonacci (n
) {
50 return fibonacci(n
- 1) + fibonacci(n
- 2)
54 * Intentionally inefficient implementation.
56 * @param {number} n - The number to calculate the factorial of.
57 * @returns {number} - The factorial of n.
59 function factorial (n
) {
63 return factorial(n
- 1) * n
67 function executeWorkerFunction (data
) {
68 switch (data
.function) {
69 case WorkerFunctions
.jsonIntegerSerialization
:
70 return jsonIntegerSerialization(data
.taskSize
|| 1000)
71 case WorkerFunctions
.fibonacci
:
72 return fibonacci(data
.taskSize
|| 1000)
73 case WorkerFunctions
.factorial
:
74 return factorial(data
.taskSize
|| 1000)
76 throw new Error('Unknown worker function')
82 executeWorkerFunction
,
83 generateRandomInteger
,