Factor out benchmarks helpers
[poolifier.git] / benchmarks / internal / thread / dynamic.js
index bc9b3d8194e91e14305419eb2265bc4bced929b3..fa2e0f83bf56c4cf4eaf62814c32e46b8206af94 100644 (file)
@@ -2,9 +2,10 @@ const {
   DynamicThreadPool,
   WorkerChoiceStrategies
 } = require('../../../lib/index')
-const { runTest } = require('../benchmark-utils')
+const { runPoolifierTest } = require('../../benchmarks-utils')
 
 const size = 30
+const numberOfTasks = 1
 
 const dynamicPool = new DynamicThreadPool(
   size / 2,
@@ -16,22 +17,50 @@ const dynamicPoolLessRecentlyUsed = new DynamicThreadPool(
   size / 2,
   size * 3,
   './benchmarks/internal/thread/worker.js',
-  { workerChoiceStrategy: DynamicThreadPool.LESS_RECENTLY_USED }
+  { workerChoiceStrategy: WorkerChoiceStrategies.LESS_RECENTLY_USED }
+)
+
+const dynamicPoolWeightedRoundRobin = new DynamicThreadPool(
+  size / 2,
+  size * 3,
+  './benchmarks/internal/thread/worker.js',
+  { workerChoiceStrategy: WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN }
+)
+
+const dynamicPoolFairShare = new DynamicThreadPool(
+  size / 2,
+  size * 3,
+  './benchmarks/internal/thread/worker.js',
+  { workerChoiceStrategy: WorkerChoiceStrategies.FAIR_SHARE }
 )
 
 async function dynamicThreadTest (
-  { tasks, workerData } = { tasks: 1, workerData: { proof: 'ok' } }
+  { tasks, workerData } = { tasks: numberOfTasks, workerData: { proof: 'ok' } }
 ) {
-  return runTest(dynamicPool, { tasks, workerData })
+  return runPoolifierTest(dynamicPool, { tasks, workerData })
 }
 
 async function dynamicThreadTestLessRecentlyUsed (
-  { tasks, workerData } = { tasks: 1, workerData: { proof: 'ok' } }
+  { tasks, workerData } = { tasks: numberOfTasks, workerData: { proof: 'ok' } }
+) {
+  return runPoolifierTest(dynamicPoolLessRecentlyUsed, { tasks, workerData })
+}
+
+async function dynamicThreadTestWeightedRoundRobin (
+  { tasks, workerData } = { tasks: numberOfTasks, workerData: { proof: 'ok' } }
+) {
+  return runPoolifierTest(dynamicPoolWeightedRoundRobin, { tasks, workerData })
+}
+
+async function dynamicThreadTestFairShare (
+  { tasks, workerData } = { tasks: numberOfTasks, workerData: { proof: 'ok' } }
 ) {
-  return runTest(dynamicPoolLessRecentlyUsed, { tasks, workerData })
+  return runPoolifierTest(dynamicPoolFairShare, { tasks, workerData })
 }
 
 module.exports = {
   dynamicThreadTest,
-  dynamicThreadTestLessRecentlyUsed
+  dynamicThreadTestLessRecentlyUsed,
+  dynamicThreadTestWeightedRoundRobin,
+  dynamicThreadTestFairShare
 }