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