| 1 | const Benchmark = require('benchmark') |
| 2 | const { |
| 3 | dynamicClusterTest, |
| 4 | dynamicClusterTestFairShare, |
| 5 | dynamicClusterTestLessRecentlyUsed, |
| 6 | dynamicClusterTestWeightedRoundRobin |
| 7 | } = require('./cluster/dynamic') |
| 8 | const { |
| 9 | fixedClusterTest, |
| 10 | fixedClusterTestFairShare, |
| 11 | fixedClusterTestLessRecentlyUsed, |
| 12 | fixedClusterTestWeightedRoundRobin |
| 13 | } = require('./cluster/fixed') |
| 14 | const { |
| 15 | dynamicThreadTest, |
| 16 | dynamicThreadTestFairShare, |
| 17 | dynamicThreadTestLessRecentlyUsed, |
| 18 | dynamicThreadTestWeightedRoundRobin |
| 19 | } = require('./thread/dynamic') |
| 20 | const { |
| 21 | fixedThreadTest, |
| 22 | fixedThreadTestFairShare, |
| 23 | fixedThreadTestLessRecentlyUsed, |
| 24 | fixedThreadTestWeightedRoundRobin |
| 25 | } = require('./thread/fixed') |
| 26 | const { LIST_FORMATTER } = require('./benchmark-utils') |
| 27 | |
| 28 | const suite = new Benchmark.Suite('poolifier') |
| 29 | |
| 30 | // Wait some seconds before start, pools need to load threads !!! |
| 31 | setTimeout(async () => { |
| 32 | test() |
| 33 | }, 3000) |
| 34 | |
| 35 | async function test () { |
| 36 | // Add tests |
| 37 | suite |
| 38 | .add('Poolifier:Fixed:ThreadPool', async function () { |
| 39 | await fixedThreadTest() |
| 40 | }) |
| 41 | .add('Poolifier:Fixed:ThreadPool:LessRecentlyUsed', async function () { |
| 42 | await fixedThreadTestLessRecentlyUsed() |
| 43 | }) |
| 44 | .add('Poolifier:Fixed:ThreadPool:WeightedRoundRobin', async function () { |
| 45 | await fixedThreadTestWeightedRoundRobin() |
| 46 | }) |
| 47 | .add('Poolifier:Fixed:ThreadPool:FairShare', async function () { |
| 48 | await fixedThreadTestFairShare() |
| 49 | }) |
| 50 | .add('Poolifier:Dynamic:ThreadPool', async function () { |
| 51 | await dynamicThreadTest() |
| 52 | }) |
| 53 | .add('Poolifier:Dynamic:ThreadPool:LessRecentlyUsed', async function () { |
| 54 | await dynamicThreadTestLessRecentlyUsed() |
| 55 | }) |
| 56 | .add('Poolifier:Dynamic:ThreadPool:WeightedRoundRobin', async function () { |
| 57 | await dynamicThreadTestWeightedRoundRobin() |
| 58 | }) |
| 59 | .add('Poolifier:Dynamic:ThreadPool:FairShare', async function () { |
| 60 | await dynamicThreadTestFairShare() |
| 61 | }) |
| 62 | .add('Poolifier:Fixed:ClusterPool', async function () { |
| 63 | await fixedClusterTest() |
| 64 | }) |
| 65 | .add('Poolifier:Fixed:ClusterPool:LessRecentlyUsed', async function () { |
| 66 | await fixedClusterTestLessRecentlyUsed() |
| 67 | }) |
| 68 | .add('Poolifier:Fixed:ClusterPool:WeightedRoundRobin', async function () { |
| 69 | await fixedClusterTestWeightedRoundRobin |
| 70 | }) |
| 71 | .add('Poolifier:Fixed:ClusterPool:FairShare', async function () { |
| 72 | await fixedClusterTestFairShare() |
| 73 | }) |
| 74 | .add('Poolifier:Dynamic:ClusterPool', async function () { |
| 75 | await dynamicClusterTest() |
| 76 | }) |
| 77 | .add('Poolifier:Dynamic:ClusterPool:LessRecentlyUsed', async function () { |
| 78 | await dynamicClusterTestLessRecentlyUsed() |
| 79 | }) |
| 80 | .add('Poolifier:Dynamic:ClusterPool:WeightedRoundRobin', async function () { |
| 81 | await dynamicClusterTestWeightedRoundRobin |
| 82 | }) |
| 83 | .add('Poolifier:Dynamic:ClusterPool:FairShare', async function () { |
| 84 | await dynamicClusterTestFairShare() |
| 85 | }) |
| 86 | // Add listeners |
| 87 | .on('cycle', function (event) { |
| 88 | console.log(event.target.toString()) |
| 89 | }) |
| 90 | .on('complete', function () { |
| 91 | console.log( |
| 92 | 'Fastest is ' + |
| 93 | LIST_FORMATTER.format(this.filter('fastest').map('name')) |
| 94 | ) |
| 95 | // eslint-disable-next-line no-process-exit |
| 96 | process.exit() |
| 97 | }) |
| 98 | .run({ async: true }) |
| 99 | } |