summaryrefslogtreecommitdiffstats
path: root/fastify-busboy/benchmarks/busboy/executioner.js
blob: 524912ce219a60e8f9acf7b11d90d68970997fd1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
'use strict'

const { process: processBusboy } = require('./contestants/busboy')
const { process: processFastify } = require('./contestants/fastify-busboy')
const { getCommonBuilder } = require('../common/commonBuilder')
const { validateAccuracy } = require('./validator')
const { resolveContestant } = require('../common/contestantResolver')
const { outputResults } = require('../common/resultUtils')

const contestants = {
  busboy: measureBusboy,
  fastify: measureFastify
}

async function measureBusboy () {
  const benchmark = getCommonBuilder()
    .benchmarkName('Busboy comparison')
    .benchmarkEntryName('busboy')
    .asyncFunctionUnderTest(processBusboy)
    .build()
  const benchmarkResults = await benchmark.executeAsync()
  outputResults(benchmark, benchmarkResults)
}

async function measureFastify () {
  const benchmark = getCommonBuilder()
    .benchmarkName('Busboy comparison')
    .benchmarkEntryName('fastify-busboy')
    .asyncFunctionUnderTest(processFastify)
    .build()
  const benchmarkResults = await benchmark.executeAsync()
  outputResults(benchmark, benchmarkResults)
}

function execute () {
  return validateAccuracy(processBusboy())
    .then(() => {
      return validateAccuracy(processFastify())
    })
    .then(() => {
      const contestant = resolveContestant(contestants)
      return contestant()
    }).then(() => {
      console.log('all done')
    }).catch((err) => {
      console.error(`Something went wrong: ${err.message}`)
    })
}

execute()