Add threadwork, microjob to external pools benchmark (#266)
[poolifier.git] / benchmarks / versus-external-pools / fixed-threadwork.js
diff --git a/benchmarks/versus-external-pools/fixed-threadwork.js b/benchmarks/versus-external-pools/fixed-threadwork.js
new file mode 100644 (file)
index 0000000..dfba6c0
--- /dev/null
@@ -0,0 +1,25 @@
+// IMPORT LIBRARIES
+const { ThreadPool } = require('threadwork')
+// FINISH IMPORT LIBRARIES
+// IMPORT FUNCTION TO BENCH
+const functionToBench = require('./functions/function-to-bench')
+// FINISH IMPORT FUNCTION TO BENCH
+const size = process.env.POOL_SIZE
+const iterations = process.env.NUM_ITERATIONS
+const data = {
+  test: 'MYBENCH',
+  taskType: process.env['TASK_TYPE']
+}
+
+const threadPool = new ThreadPool({ task: functionToBench, size: size })
+
+async function run () {
+  const promises = []
+  for (let i = 0; i < iterations; i++) {
+    promises.push(threadPool.run(data))
+  }
+  await Promise.all(promises)
+  process.exit()
+}
+
+run()