Fix benchmarks run: use synchronous call.
[poolifier.git] / benchmarks / bench.js
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, my 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 }