chore: v2.4.0-3
[poolifier.git] / benchmarks / internal / bench.js
index f942595565fde1d5f749bbade274b53e947bd9b4..218648281fca341b0566fe977f30d0acbe893321 100644 (file)
-const Benchmark = require('benchmark')
+const Benchmark = require('benny')
 const {
   dynamicClusterTest,
   dynamicClusterTestFairShare,
-  dynamicClusterTestLessRecentlyUsed,
-  dynamicClusterTestWeightedRoundRobin
+  dynamicClusterTestLessUsed,
+  dynamicClusterTestWeightedRoundRobin,
+  dynamicClusterTestLessBusy
 } = require('./cluster/dynamic')
 const {
   fixedClusterTest,
   fixedClusterTestFairShare,
-  fixedClusterTestLessRecentlyUsed,
-  fixedClusterTestWeightedRoundRobin
+  fixedClusterTestLessUsed,
+  fixedClusterTestWeightedRoundRobin,
+  fixedClusterTestLessBusy
 } = require('./cluster/fixed')
 const {
   dynamicThreadTest,
   dynamicThreadTestFairShare,
-  dynamicThreadTestLessRecentlyUsed,
-  dynamicThreadTestWeightedRoundRobin
+  dynamicThreadTestLessUsed,
+  dynamicThreadTestWeightedRoundRobin,
+  dynamicThreadTestLessBusy
 } = require('./thread/dynamic')
 const {
   fixedThreadTest,
   fixedThreadTestFairShare,
-  fixedThreadTestLessRecentlyUsed,
-  fixedThreadTestWeightedRoundRobin
+  fixedThreadTestLessUsed,
+  fixedThreadTestWeightedRoundRobin,
+  fixedThreadTestLessBusy
 } = require('./thread/fixed')
-const { LIST_FORMATTER } = require('../benchmarks-utils')
 
-const suite = new Benchmark.Suite('poolifier')
+const resultsFile = 'poolifier'
+const resultsFolder = 'benchmarks/internal/results'
 
-// Wait some seconds before start, pools need to load threads !!!
-setTimeout(async () => {
-  test()
-}, 3000)
-
-async function test () {
-  // Add tests
-  suite
-    .add('Poolifier:Fixed:ThreadPool', async function () {
-      await fixedThreadTest()
-    })
-    .add('Poolifier:Fixed:ThreadPool:LessRecentlyUsed', async function () {
-      await fixedThreadTestLessRecentlyUsed()
-    })
-    .add('Poolifier:Fixed:ThreadPool:WeightedRoundRobin', async function () {
-      await fixedThreadTestWeightedRoundRobin()
-    })
-    .add('Poolifier:Fixed:ThreadPool:FairShare', async function () {
-      await fixedThreadTestFairShare()
-    })
-    .add('Poolifier:Dynamic:ThreadPool', async function () {
-      await dynamicThreadTest()
-    })
-    .add('Poolifier:Dynamic:ThreadPool:LessRecentlyUsed', async function () {
-      await dynamicThreadTestLessRecentlyUsed()
-    })
-    .add('Poolifier:Dynamic:ThreadPool:WeightedRoundRobin', async function () {
-      await dynamicThreadTestWeightedRoundRobin()
-    })
-    .add('Poolifier:Dynamic:ThreadPool:FairShare', async function () {
-      await dynamicThreadTestFairShare()
-    })
-    .add('Poolifier:Fixed:ClusterPool', async function () {
-      await fixedClusterTest()
-    })
-    .add('Poolifier:Fixed:ClusterPool:LessRecentlyUsed', async function () {
-      await fixedClusterTestLessRecentlyUsed()
-    })
-    .add('Poolifier:Fixed:ClusterPool:WeightedRoundRobin', async function () {
-      await fixedClusterTestWeightedRoundRobin
-    })
-    .add('Poolifier:Fixed:ClusterPool:FairShare', async function () {
-      await fixedClusterTestFairShare()
-    })
-    .add('Poolifier:Dynamic:ClusterPool', async function () {
-      await dynamicClusterTest()
-    })
-    .add('Poolifier:Dynamic:ClusterPool:LessRecentlyUsed', async function () {
-      await dynamicClusterTestLessRecentlyUsed()
-    })
-    .add('Poolifier:Dynamic:ClusterPool:WeightedRoundRobin', async function () {
-      await dynamicClusterTestWeightedRoundRobin
-    })
-    .add('Poolifier:Dynamic:ClusterPool:FairShare', async function () {
-      await dynamicClusterTestFairShare()
-    })
-    // Add listeners
-    .on('cycle', function (event) {
-      console.log(event.target.toString())
-    })
-    .on('complete', function () {
-      console.log(
-        'Fastest is ' +
-          LIST_FORMATTER.format(this.filter('fastest').map('name'))
-      )
-      // eslint-disable-next-line no-process-exit
-      process.exit()
-    })
-    .run({ async: true })
-}
+Benchmark.suite(
+  'Poolifier',
+  Benchmark.add('Poolifier:Fixed:ThreadPool', async () => {
+    await fixedThreadTest()
+  }),
+  Benchmark.add('Poolifier:Fixed:ThreadPool:LessUsed', async () => {
+    await fixedThreadTestLessUsed()
+  }),
+  Benchmark.add('Poolifier:Fixed:ThreadPool:LessBusy', async () => {
+    await fixedThreadTestLessBusy()
+  }),
+  Benchmark.add('Poolifier:Fixed:ThreadPool:WeightedRoundRobin', async () => {
+    await fixedThreadTestWeightedRoundRobin()
+  }),
+  Benchmark.add('Poolifier:Fixed:ThreadPool:FairShare', async () => {
+    await fixedThreadTestFairShare()
+  }),
+  Benchmark.add('Poolifier:Dynamic:ThreadPool', async () => {
+    await dynamicThreadTest()
+  }),
+  Benchmark.add('Poolifier:Dynamic:ThreadPool:LessUsed', async () => {
+    await dynamicThreadTestLessUsed()
+  }),
+  Benchmark.add('Poolifier:Dynamic:ThreadPool:LessBusy', async () => {
+    await dynamicThreadTestLessBusy()
+  }),
+  Benchmark.add('Poolifier:Dynamic:ThreadPool:WeightedRoundRobin', async () => {
+    await dynamicThreadTestWeightedRoundRobin()
+  }),
+  Benchmark.add('Poolifier:Dynamic:ThreadPool:FairShare', async () => {
+    await dynamicThreadTestFairShare()
+  }),
+  Benchmark.add('Poolifier:Fixed:ClusterPool', async () => {
+    await fixedClusterTest()
+  }),
+  Benchmark.add('Poolifier:Fixed:ClusterPool:LessUsed', async () => {
+    await fixedClusterTestLessUsed()
+  }),
+  Benchmark.add('Poolifier:Fixed:ClusterPool:LessBusy', async () => {
+    await fixedClusterTestLessBusy()
+  }),
+  Benchmark.add('Poolifier:Fixed:ClusterPool:WeightedRoundRobin', async () => {
+    await fixedClusterTestWeightedRoundRobin()
+  }),
+  Benchmark.add('Poolifier:Fixed:ClusterPool:FairShare', async () => {
+    await fixedClusterTestFairShare()
+  }),
+  Benchmark.add('Poolifier:Dynamic:ClusterPool', async () => {
+    await dynamicClusterTest()
+  }),
+  Benchmark.add('Poolifier:Dynamic:ClusterPool:LessUsed', async () => {
+    await dynamicClusterTestLessUsed()
+  }),
+  Benchmark.add('Poolifier:Dynamic:ClusterPool:LessBusy', async () => {
+    await dynamicClusterTestLessBusy()
+  }),
+  Benchmark.add(
+    'Poolifier:Dynamic:ClusterPool:WeightedRoundRobin',
+    async () => {
+      await dynamicClusterTestWeightedRoundRobin()
+    }
+  ),
+  Benchmark.add('Poolifier:Dynamic:ClusterPool:FairShare', async () => {
+    await dynamicClusterTestFairShare()
+  }),
+  Benchmark.cycle(),
+  Benchmark.complete(),
+  Benchmark.save({
+    file: resultsFile,
+    folder: resultsFolder,
+    format: 'json',
+    details: true
+  }),
+  Benchmark.save({
+    file: resultsFile,
+    folder: resultsFolder,
+    format: 'chart.html',
+    details: true
+  }),
+  Benchmark.save({
+    file: resultsFile,
+    folder: resultsFolder,
+    format: 'table.html',
+    details: true
+  })
+)
+  .then(() => {
+    // eslint-disable-next-line n/no-process-exit
+    return process.exit()
+  })
+  .catch(err => console.error(err))