| 1 | const Benchmark = require('benchmark') |
| 2 | const { dynamicClusterTest } = require('./cluster/dynamic') |
| 3 | const { fixedClusterTest } = require('./cluster/fixed') |
| 4 | const { dynamicThreadTest } = require('./thread/dynamic') |
| 5 | const { fixedThreadTest } = require('./thread/fixed') |
| 6 | |
| 7 | const suite = new Benchmark.Suite() |
| 8 | |
| 9 | const LIST_FORMATTER = new Intl.ListFormat('en-US', { |
| 10 | style: 'long', |
| 11 | type: 'conjunction' |
| 12 | }) |
| 13 | |
| 14 | // Wait some seconds before start, pools need to load threads !!! |
| 15 | setTimeout(async () => { |
| 16 | test() |
| 17 | }, 3000) |
| 18 | |
| 19 | async function test () { |
| 20 | // Add tests |
| 21 | suite |
| 22 | .add('Pioardi:Static:ThreadPool', async function () { |
| 23 | await fixedThreadTest() |
| 24 | }) |
| 25 | .add('Pioardi:Dynamic:ThreadPool', async function () { |
| 26 | await dynamicThreadTest() |
| 27 | }) |
| 28 | .add('Pioardi:Static:ClusterPool', async function () { |
| 29 | await fixedClusterTest() |
| 30 | }) |
| 31 | .add('Pioardi:Dynamic:ClusterPool', async function () { |
| 32 | await dynamicClusterTest() |
| 33 | }) |
| 34 | // Add listeners |
| 35 | .on('cycle', function (event) { |
| 36 | console.log(event.target.toString()) |
| 37 | }) |
| 38 | .on('complete', function () { |
| 39 | console.log( |
| 40 | 'Fastest is ' + |
| 41 | LIST_FORMATTER.format(this.filter('fastest').map('name')) |
| 42 | ) |
| 43 | // eslint-disable-next-line no-process-exit |
| 44 | process.exit() |
| 45 | }) |
| 46 | .run() |
| 47 | } |