X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=benchmarks%2Finternal%2Fbench.js;h=218648281fca341b0566fe977f30d0acbe893321;hb=refs%2Ftags%2Fv2.4.0-3;hp=f3a1eb4fda07db3328704cf300f2afb1707a91f4;hpb=2f8c5b5c1182f698efe07d327359bef934af3a29;p=poolifier.git diff --git a/benchmarks/internal/bench.js b/benchmarks/internal/bench.js index f3a1eb4f..21864828 100644 --- a/benchmarks/internal/bench.js +++ b/benchmarks/internal/bench.js @@ -1,99 +1,124 @@ -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 n/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))