Switch eslint-plugin-node to supported eslint-plugin-n
[poolifier.git] / benchmarks / internal / bench.js
CommitLineData
57df5469 1const Benchmark = require('benchmark')
ff5e76e1
JB
2const {
3 dynamicClusterTest,
23ff945a 4 dynamicClusterTestFairShare,
2d401b2d
JB
5 dynamicClusterTestLessRecentlyUsed,
6 dynamicClusterTestWeightedRoundRobin
ff5e76e1 7} = require('./cluster/dynamic')
292ad316
JB
8const {
9 fixedClusterTest,
23ff945a 10 fixedClusterTestFairShare,
2d401b2d
JB
11 fixedClusterTestLessRecentlyUsed,
12 fixedClusterTestWeightedRoundRobin
292ad316 13} = require('./cluster/fixed')
ff5e76e1
JB
14const {
15 dynamicThreadTest,
23ff945a 16 dynamicThreadTestFairShare,
2d401b2d
JB
17 dynamicThreadTestLessRecentlyUsed,
18 dynamicThreadTestWeightedRoundRobin
ff5e76e1 19} = require('./thread/dynamic')
292ad316
JB
20const {
21 fixedThreadTest,
23ff945a 22 fixedThreadTestFairShare,
2d401b2d
JB
23 fixedThreadTestLessRecentlyUsed,
24 fixedThreadTestWeightedRoundRobin
292ad316 25} = require('./thread/fixed')
d1a9aa41 26const { LIST_FORMATTER } = require('../benchmarks-utils')
325f50bc 27
ff5e76e1 28const suite = new Benchmark.Suite('poolifier')
57df5469 29
85a3f8a7 30// Wait some seconds before start, pools need to load threads !!!
57df5469 31setTimeout(async () => {
32 test()
33}, 3000)
34
106744f7 35async function test () {
85a3f8a7 36 // Add tests
cf9aa6c3 37 suite
292ad316 38 .add('Poolifier:Fixed:ThreadPool', async function () {
325f50bc
S
39 await fixedThreadTest()
40 })
292ad316
JB
41 .add('Poolifier:Fixed:ThreadPool:LessRecentlyUsed', async function () {
42 await fixedThreadTestLessRecentlyUsed()
43 })
2d401b2d
JB
44 .add('Poolifier:Fixed:ThreadPool:WeightedRoundRobin', async function () {
45 await fixedThreadTestWeightedRoundRobin()
46 })
23ff945a
JB
47 .add('Poolifier:Fixed:ThreadPool:FairShare', async function () {
48 await fixedThreadTestFairShare()
49 })
ff5e76e1 50 .add('Poolifier:Dynamic:ThreadPool', async function () {
325f50bc
S
51 await dynamicThreadTest()
52 })
ff5e76e1
JB
53 .add('Poolifier:Dynamic:ThreadPool:LessRecentlyUsed', async function () {
54 await dynamicThreadTestLessRecentlyUsed()
55 })
2d401b2d
JB
56 .add('Poolifier:Dynamic:ThreadPool:WeightedRoundRobin', async function () {
57 await dynamicThreadTestWeightedRoundRobin()
58 })
23ff945a
JB
59 .add('Poolifier:Dynamic:ThreadPool:FairShare', async function () {
60 await dynamicThreadTestFairShare()
61 })
292ad316 62 .add('Poolifier:Fixed:ClusterPool', async function () {
325f50bc 63 await fixedClusterTest()
cf9aa6c3 64 })
292ad316
JB
65 .add('Poolifier:Fixed:ClusterPool:LessRecentlyUsed', async function () {
66 await fixedClusterTestLessRecentlyUsed()
67 })
2d401b2d
JB
68 .add('Poolifier:Fixed:ClusterPool:WeightedRoundRobin', async function () {
69 await fixedClusterTestWeightedRoundRobin
70 })
23ff945a
JB
71 .add('Poolifier:Fixed:ClusterPool:FairShare', async function () {
72 await fixedClusterTestFairShare()
73 })
ff5e76e1 74 .add('Poolifier:Dynamic:ClusterPool', async function () {
325f50bc 75 await dynamicClusterTest()
106744f7 76 })
ff5e76e1
JB
77 .add('Poolifier:Dynamic:ClusterPool:LessRecentlyUsed', async function () {
78 await dynamicClusterTestLessRecentlyUsed()
79 })
2d401b2d
JB
80 .add('Poolifier:Dynamic:ClusterPool:WeightedRoundRobin', async function () {
81 await dynamicClusterTestWeightedRoundRobin
82 })
23ff945a
JB
83 .add('Poolifier:Dynamic:ClusterPool:FairShare', async function () {
84 await dynamicClusterTestFairShare()
85 })
85a3f8a7 86 // Add listeners
57df5469 87 .on('cycle', function (event) {
583a27ce 88 console.log(event.target.toString())
57df5469 89 })
90 .on('complete', function () {
583a27ce
JB
91 console.log(
92 'Fastest is ' +
93 LIST_FORMATTER.format(this.filter('fastest').map('name'))
94 )
2f8c5b5c 95 // eslint-disable-next-line n/no-process-exit
583a27ce 96 process.exit()
57df5469 97 })
292ad316 98 .run({ async: true })
57df5469 99}