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