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