| 1 | 'use strict' |
| 2 | |
| 3 | const { process: processBusboy } = require('./contestants/busboy') |
| 4 | const { process: processFastify } = require('./contestants/fastify-busboy') |
| 5 | const { getCommonBuilder } = require('../common/commonBuilder') |
| 6 | const { validateAccuracy } = require('./validator') |
| 7 | const { resolveContestant } = require('../common/contestantResolver') |
| 8 | const { outputResults } = require('../common/resultUtils') |
| 9 | |
| 10 | const contestants = { |
| 11 | busboy: measureBusboy, |
| 12 | fastify: measureFastify |
| 13 | } |
| 14 | |
| 15 | async function measureBusboy () { |
| 16 | const benchmark = getCommonBuilder() |
| 17 | .benchmarkName('Busboy comparison') |
| 18 | .benchmarkEntryName('busboy') |
| 19 | .asyncFunctionUnderTest(processBusboy) |
| 20 | .build() |
| 21 | const benchmarkResults = await benchmark.executeAsync() |
| 22 | outputResults(benchmark, benchmarkResults) |
| 23 | } |
| 24 | |
| 25 | async function measureFastify () { |
| 26 | const benchmark = getCommonBuilder() |
| 27 | .benchmarkName('Busboy comparison') |
| 28 | .benchmarkEntryName('fastify-busboy') |
| 29 | .asyncFunctionUnderTest(processFastify) |
| 30 | .build() |
| 31 | const benchmarkResults = await benchmark.executeAsync() |
| 32 | outputResults(benchmark, benchmarkResults) |
| 33 | } |
| 34 | |
| 35 | function execute () { |
| 36 | return validateAccuracy(processBusboy()) |
| 37 | .then(() => { |
| 38 | return validateAccuracy(processFastify()) |
| 39 | }) |
| 40 | .then(() => { |
| 41 | const contestant = resolveContestant(contestants) |
| 42 | return contestant() |
| 43 | }).then(() => { |
| 44 | console.log('all done') |
| 45 | }).catch((err) => { |
| 46 | console.error(`Something went wrong: ${err.message}`) |
| 47 | }) |
| 48 | } |
| 49 | |
| 50 | execute() |