c04162e1a617d704708b56496040640947e22171
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
70 function executeWorkerFunction (data
) {
71 switch (data
.function) {
72 case WorkerFunctions
.jsonIntegerSerialization
:
73 return jsonIntegerSerialization(data
.taskSize
|| 1000)
74 case WorkerFunctions
.fibonacci
:
75 return fibonacci(data
.taskSize
|| 1000)
76 case WorkerFunctions
.factorial
:
77 return factorial(data
.taskSize
|| 1000)
79 throw new Error('Unknown worker function')
85 executeWorkerFunction
,
86 generateRandomInteger
,