e6abe96d5b1e065c07b709bd83c37095e9996935
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) {
34 if (max
< min
|| max
< 0 || min
< 0) {
35 throw new RangeError('Invalid interval')
38 if (min
!= null && min
!== 0) {
40 return Math
.floor(Math
.random() * (max
- min
+ 1)) + min
42 return Math
.floor(Math
.random() * (max
+ 1))
46 * Intentionally inefficient implementation.
48 * @param {number} n - The number of fibonacci numbers to generate.
49 * @returns {number} - The nth fibonacci number.
51 function fibonacci (n
) {
53 return fibonacci(n
- 1) + fibonacci(n
- 2)
57 * Intentionally inefficient implementation.
59 * @param {number} n - The number to calculate the factorial of.
60 * @returns {number} - The factorial of n.
62 function factorial (n
) {
66 return factorial(n
- 1) * n
69 function executeWorkerFunction (data
) {
70 switch (data
.function) {
71 case WorkerFunctions
.jsonIntegerSerialization
:
72 return jsonIntegerSerialization(data
.taskSize
|| 1000)
73 case WorkerFunctions
.fibonacci
:
74 return fibonacci(data
.taskSize
|| 1000)
75 case WorkerFunctions
.factorial
:
76 return factorial(data
.taskSize
|| 1000)
78 throw new Error('Unknown worker function')
84 executeWorkerFunction
,
85 generateRandomInteger
,