Add benchmark for quick select algorithm evaluation. (#255)
[poolifier.git] / benchmarks / internal / thread / dynamic.js
1 const {
2 DynamicThreadPool,
3 WorkerChoiceStrategies
4 } = require('../../../lib/index')
5 const { runPoolifierTest } = require('../benchmark-utils')
6
7 const size = 30
8
9 const dynamicPool = new DynamicThreadPool(
10 size / 2,
11 size * 3,
12 './benchmarks/internal/thread/worker.js'
13 )
14
15 const dynamicPoolLessRecentlyUsed = new DynamicThreadPool(
16 size / 2,
17 size * 3,
18 './benchmarks/internal/thread/worker.js',
19 { workerChoiceStrategy: WorkerChoiceStrategies.LESS_RECENTLY_USED }
20 )
21
22 async function dynamicThreadTest (
23 { tasks, workerData } = { tasks: 1, workerData: { proof: 'ok' } }
24 ) {
25 return runPoolifierTest(dynamicPool, { tasks, workerData })
26 }
27
28 async function dynamicThreadTestLessRecentlyUsed (
29 { tasks, workerData } = { tasks: 1, workerData: { proof: 'ok' } }
30 ) {
31 return runPoolifierTest(dynamicPoolLessRecentlyUsed, { tasks, workerData })
32 }
33
34 module.exports = {
35 dynamicThreadTest,
36 dynamicThreadTestLessRecentlyUsed
37 }