Properly name and separate each steps at publication. (#199)
[poolifier.git] / benchmarks / bench.js
CommitLineData
57df5469 1const Benchmark = require('benchmark')
325f50bc
S
2const { dynamicClusterTest } = require('./cluster/dynamic')
3const { fixedClusterTest } = require('./cluster/fixed')
4const { dynamicThreadTest } = require('./thread/dynamic')
5const { fixedThreadTest } = require('./thread/fixed')
6
57df5469 7const suite = new Benchmark.Suite()
57df5469 8
583a27ce
JB
9const LIST_FORMATTER = new Intl.ListFormat('en-US', {
10 style: 'long',
11 type: 'conjunction'
12})
13
85a3f8a7 14// Wait some seconds before start, pools need to load threads !!!
57df5469 15setTimeout(async () => {
16 test()
17}, 3000)
18
106744f7 19async function test () {
85a3f8a7 20 // Add tests
cf9aa6c3 21 suite
325f50bc
S
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()
cf9aa6c3 30 })
325f50bc
S
31 .add('Pioardi:Dynamic:ClusterPool', async function () {
32 await dynamicClusterTest()
106744f7 33 })
85a3f8a7 34 // Add listeners
57df5469 35 .on('cycle', function (event) {
583a27ce 36 console.log(event.target.toString())
57df5469 37 })
38 .on('complete', function () {
583a27ce
JB
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()
57df5469 45 })
080e4814 46 .run()
57df5469 47}