Added prettier standard to support prettier and use it in combination with standard
[poolifier.git] / benchmarks / myBench.js
index 9c1d713fc6820f8e3cefaa64a5785b13d50ae8ec..8835f1f5d4cec31feba03012fc7974df02810f91 100644 (file)
@@ -6,8 +6,15 @@ const size = 16
 
 // 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 }
+)
 
 // data
 const workerData = { proof: 'ok' }
@@ -19,7 +26,11 @@ async function fixedTest () {
   for (let i = 0; i <= tasks; i++) {
     fixedPool.execute(workerData).then(res => {
       executions++
-      if (executions === tasks) console.log(`Fixed pool take ${Date.now() - time} to work on ${executions} tasks`)
+      if (executions === tasks) {
+        console.log(
+          `Fixed pool take ${Date.now() - time} to work on ${executions} tasks`
+        )
+      }
     })
   }
 }
@@ -30,7 +41,12 @@ async function dynamicTest () {
   for (let i = 0; i <= tasks; i++) {
     dynamicPool.execute(workerData).then(res => {
       executions++
-      if (executions === tasks) console.log(`Dynamic pool take ${Date.now() - time} to work on ${executions} tasks`)
+      if (executions === tasks) {
+        console.log(
+          `Dynamic pool take ${Date.now() -
+            time} to work on ${executions} tasks`
+        )
+      }
     })
   }
 }
@@ -40,18 +56,27 @@ async function externalPoolTest () {
   const time = Date.now()
   for (let i = 0; i <= tasks; i++) {
     new Promise((resolve, reject) => {
-      externalPool.acquire('./externalWorker.js', { workerData: workerData }, (err, worker) => {
-        if (err) {
-          return reject(err)
+      externalPool.acquire(
+        './externalWorker.js',
+        { workerData: workerData },
+        (err, worker) => {
+          if (err) {
+            return reject(err)
+          }
+          worker.on('error', reject)
+          worker.on('message', res => {
+            executions++
+            resolve(res)
+          })
         }
-        worker.on('error', reject)
-        worker.on('message', res => {
-          executions++
-          resolve(res)
-        })
-      })
+      )
     }).then(res => {
-      if (tasks === executions) console.log(`External pool take ${Date.now() - time} to work  on ${executions} tasks`)
+      if (tasks === executions) {
+        console.log(
+          `External pool take ${Date.now() -
+            time} to work  on ${executions} tasks`
+        )
+      }
     })
   }
 }