Benchmarks and performance enhancements (#209)
[poolifier.git] / benchmarks / versus-external-pools / dynamic-suchmokuo-node-worker-threads-pool.js
diff --git a/benchmarks/versus-external-pools/dynamic-suchmokuo-node-worker-threads-pool.js b/benchmarks/versus-external-pools/dynamic-suchmokuo-node-worker-threads-pool.js
new file mode 100644 (file)
index 0000000..8bf964d
--- /dev/null
@@ -0,0 +1,29 @@
+// IMPORT LIBRARIES
+const { DynamicPool, StaticPool } = require('node-worker-threads-pool')
+// FINISH IMPORT LIBRARIES
+// IMPORT FUNCTION TO BENCH
+const functionToBench = require('./functions/json-stringify')
+// FINISH IMPORT FUNCTION TO BENCH
+const size = process.env.POOL_SIZE
+const iterations = process.env.NUM_ITERATIONS
+const data = {
+  test: 'MYBENCH'
+}
+
+const pool = new DynamicPool(Number(size))
+
+async function run () {
+  const promises = []
+  for (let i = 0; i < iterations; i++) {
+    promises.push(
+      pool.exec({
+        task: functionToBench,
+        param: data
+      })
+    )
+  }
+  await Promise.all(promises)
+  process.exit()
+}
+
+run()