chore: add changelog entry
[poolifier.git] / benchmarks / internal / bench.js
index 2ad7f22c5e47ec7827366ed3c95b21a3402c06cf..e88f40cf9334f5daf0ed32fb1c525c9939d7ede5 100644 (file)
-const Benchmark = require('benchmark')
-const { dynamicClusterTest } = require('./cluster/dynamic')
-const { fixedClusterTest } = require('./cluster/fixed')
-const { dynamicThreadTest } = require('./thread/dynamic')
-const { fixedThreadTest } = require('./thread/fixed')
+const Benchmark = require('benny')
+const {
+  dynamicClusterTest,
+  dynamicClusterTestFairShare,
+  dynamicClusterTestLessRecentlyUsed,
+  dynamicClusterTestWeightedRoundRobin
+} = require('./cluster/dynamic')
+const {
+  fixedClusterTest,
+  fixedClusterTestFairShare,
+  fixedClusterTestLessRecentlyUsed,
+  fixedClusterTestWeightedRoundRobin
+} = require('./cluster/fixed')
+const {
+  dynamicThreadTest,
+  dynamicThreadTestFairShare,
+  dynamicThreadTestLessRecentlyUsed,
+  dynamicThreadTestWeightedRoundRobin
+} = require('./thread/dynamic')
+const {
+  fixedThreadTest,
+  fixedThreadTestFairShare,
+  fixedThreadTestLessRecentlyUsed,
+  fixedThreadTestWeightedRoundRobin
+} = require('./thread/fixed')
 
-const suite = new Benchmark.Suite()
+const resultsFile = 'poolifier'
+const resultsFolder = 'benchmarks/internal/results'
 
-const LIST_FORMATTER = new Intl.ListFormat('en-US', {
-  style: 'long',
-  type: 'conjunction'
-})
-
-// Wait some seconds before start, pools need to load threads !!!
-setTimeout(async () => {
-  test()
-}, 3000)
-
-async function test () {
-  // Add tests
-  suite
-    .add('Pioardi:Static:ThreadPool', async function () {
-      await fixedThreadTest()
-    })
-    .add('Pioardi:Dynamic:ThreadPool', async function () {
-      await dynamicThreadTest()
-    })
-    .add('Pioardi:Static:ClusterPool', async function () {
-      await fixedClusterTest()
-    })
-    .add('Pioardi:Dynamic:ClusterPool', async function () {
-      await dynamicClusterTest()
-    })
-    // 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()
-}
+Benchmark.suite(
+  'Poolifier',
+  Benchmark.add('Poolifier:Fixed:ThreadPool', async () => {
+    await fixedThreadTest()
+  }),
+  Benchmark.add('Poolifier:Fixed:ThreadPool:LessRecentlyUsed', async () => {
+    await fixedThreadTestLessRecentlyUsed()
+  }),
+  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:LessRecentlyUsed', async () => {
+    await dynamicThreadTestLessRecentlyUsed()
+  }),
+  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:LessRecentlyUsed', async () => {
+    await fixedClusterTestLessRecentlyUsed()
+  }),
+  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:LessRecentlyUsed', async () => {
+    await dynamicClusterTestLessRecentlyUsed()
+  }),
+  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))