Add node TS type definition (#101)
[poolifier.git] / benchmarks / bench.js
index d7b2f1a36c322f29b5745bcd527ccd159113a903..e0daca2d0aa84a85387f23414b884b1c57170f2d 100644 (file)
@@ -2,15 +2,19 @@ const Benchmark = require('benchmark')
 const suite = new Benchmark.Suite()
 const FixedThreadPool = require('../lib/fixed')
 const DynamicThreadPool = require('../lib/dynamic')
-const Pool = require('worker-threads-pool')
 const size = 30
 const tasks = 1
 
 // pools
-const externalPool = new Pool({ max: size })
-const fixedPool = new FixedThreadPool(size,
-  './yourWorker.js', { maxTasks: 10000 })
-const dynamicPool = new DynamicThreadPool(size / 2, size * 3, './yourWorker.js', { maxTasks: 10000 })
+const fixedPool = new FixedThreadPool(size, './yourWorker.js', {
+  maxTasks: 10000
+})
+const dynamicPool = new DynamicThreadPool(
+  size / 2,
+  size * 3,
+  './yourWorker.js',
+  { maxTasks: 10000 }
+)
 const workerData = { proof: 'ok' }
 
 // wait some seconds before start, my pools need to load threads !!!
@@ -47,42 +51,16 @@ async function dynamicTest () {
   })
 }
 
-async function externalPoolTest () {
-  return new Promise((resolve, reject) => {
-    let executions = 0
-    for (let i = 0; i <= tasks; i++) {
-      new Promise((resolve, reject) => {
-        externalPool.acquire('./externalWorker.js', { workerData: workerData }, (err, worker) => {
-          if (err) {
-            return reject(err)
-          }
-          worker.on('error', reject)
-          worker.on('message', res => {
-            executions++
-            resolve(res)
-          })
-        })
-      }).then(res => {
-        if (tasks === executions) {
-          resolve('FINISH')
-        }
-      })
-    }
-  })
-}
-
 async function test () {
   // add tests
-  suite.add('PioardiStaticPool', async function () {
-    await fixedTest()
-  })
+  suite
+    .add('PioardiStaticPool', async function () {
+      await fixedTest()
+    })
     .add('PioardiDynamicPool', async function () {
       await dynamicTest()
     })
-    .add('ExternalPool', async function () {
-      await externalPoolTest()
-    })
-  // add listeners
+    // add listeners
     .on('cycle', function (event) {
       console.log(String(event.target))
     })
@@ -90,6 +68,6 @@ async function test () {
       this.filter('fastest').map('name')
       console.log('Fastest is ' + this.filter('fastest').map('name'))
     })
-  // run async
+    // run async
     .run({ async: true })
 }