summaryrefslogtreecommitdiffstats
path: root/fastify-busboy/benchmarks/common
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-21 20:56:19 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-21 20:56:19 +0000
commit0b6210cd37b68b94252cb798598b12974a20e1c1 (patch)
treee371686554a877842d95aa94f100bee552ff2a8e /fastify-busboy/benchmarks/common
parentInitial commit. (diff)
downloadnode-undici-0b6210cd37b68b94252cb798598b12974a20e1c1.tar.xz
node-undici-0b6210cd37b68b94252cb798598b12974a20e1c1.zip
Adding upstream version 5.28.2+dfsg1+~cs23.11.12.3.upstream/5.28.2+dfsg1+_cs23.11.12.3upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'fastify-busboy/benchmarks/common')
-rw-r--r--fastify-busboy/benchmarks/common/commonBuilder.js46
-rw-r--r--fastify-busboy/benchmarks/common/contestantResolver.js26
-rw-r--r--fastify-busboy/benchmarks/common/executionUtils.js18
-rw-r--r--fastify-busboy/benchmarks/common/resultUtils.js17
-rw-r--r--fastify-busboy/benchmarks/common/resultsCombinator.js54
5 files changed, 161 insertions, 0 deletions
diff --git a/fastify-busboy/benchmarks/common/commonBuilder.js b/fastify-busboy/benchmarks/common/commonBuilder.js
new file mode 100644
index 0000000..b5707aa
--- /dev/null
+++ b/fastify-busboy/benchmarks/common/commonBuilder.js
@@ -0,0 +1,46 @@
+'use strict'
+
+const { validateNotNil } = require('validation-utils')
+const { BenchmarkBuilder } = require('photofinish')
+const getopts = require('getopts')
+
+const options = getopts(process.argv.slice(1), {
+ alias: {
+ preset: 'p'
+ },
+ default: {}
+})
+
+const PRESET = {
+ LOW: (builder) => {
+ return builder
+ .warmupCycles(1000)
+ .benchmarkCycles(1000)
+ },
+
+ MEDIUM: (builder) => {
+ return builder
+ .warmupCycles(1000)
+ .benchmarkCycles(2000)
+ },
+
+ HIGH: (builder) => {
+ return builder
+ .warmupCycles(1000)
+ .benchmarkCycles(10000)
+ }
+}
+
+function getCommonBuilder () {
+ const presetId = options.preset || 'MEDIUM'
+ const preset = validateNotNil(PRESET[presetId.toUpperCase()], `Unknown preset: ${presetId}`)
+
+ const builder = new BenchmarkBuilder()
+ preset(builder)
+ return builder
+ .benchmarkCycleSamples(50)
+}
+
+module.exports = {
+ getCommonBuilder
+}
diff --git a/fastify-busboy/benchmarks/common/contestantResolver.js b/fastify-busboy/benchmarks/common/contestantResolver.js
new file mode 100644
index 0000000..7cfc90e
--- /dev/null
+++ b/fastify-busboy/benchmarks/common/contestantResolver.js
@@ -0,0 +1,26 @@
+'use strict'
+
+const getopts = require('getopts')
+
+const options = getopts(process.argv.slice(1), {
+ alias: {
+ contestant: 'c'
+ },
+ default: {}
+})
+
+function resolveContestant (contestants) {
+ const contestantId = options.contestant
+ const contestant = Number.isFinite(contestantId)
+ ? Object.values(contestants)[contestantId]
+ : contestants[contestantId]
+
+ if (!contestant) {
+ throw new Error(`Unknown contestant ${contestantId}`)
+ }
+ return contestant
+}
+
+module.exports = {
+ resolveContestant
+}
diff --git a/fastify-busboy/benchmarks/common/executionUtils.js b/fastify-busboy/benchmarks/common/executionUtils.js
new file mode 100644
index 0000000..8c52ec8
--- /dev/null
+++ b/fastify-busboy/benchmarks/common/executionUtils.js
@@ -0,0 +1,18 @@
+'use strict'
+
+const { getCommonBuilder } = require('./commonBuilder')
+const { outputResults } = require('./resultUtils')
+
+function getMeasureFn (constestandId, fn) {
+ return () => {
+ const benchmark = getCommonBuilder()
+ .benchmarkEntryName(constestandId)
+ .functionUnderTest(fn).build()
+ const benchmarkResults = benchmark.execute()
+ outputResults(benchmark, benchmarkResults)
+ }
+}
+
+module.exports = {
+ getMeasureFn
+}
diff --git a/fastify-busboy/benchmarks/common/resultUtils.js b/fastify-busboy/benchmarks/common/resultUtils.js
new file mode 100644
index 0000000..ec7bce7
--- /dev/null
+++ b/fastify-busboy/benchmarks/common/resultUtils.js
@@ -0,0 +1,17 @@
+'use strict'
+
+const { exportResults } = require('photofinish')
+
+function outputResults (benchmark, benchmarkResults) {
+ console.log(
+ `Mean time for ${
+ benchmark.benchmarkEntryName
+ } is ${benchmarkResults.meanTime.getTimeInNanoSeconds()} nanoseconds`
+ )
+
+ exportResults(benchmarkResults, { exportPath: '_results' })
+}
+
+module.exports = {
+ outputResults
+}
diff --git a/fastify-busboy/benchmarks/common/resultsCombinator.js b/fastify-busboy/benchmarks/common/resultsCombinator.js
new file mode 100644
index 0000000..253211b
--- /dev/null
+++ b/fastify-busboy/benchmarks/common/resultsCombinator.js
@@ -0,0 +1,54 @@
+'use strict'
+
+const fs = require('node:fs')
+const path = require('node:path')
+const getopts = require('getopts')
+const systemInformation = require('systeminformation')
+const { loadResults } = require('photofinish')
+
+const options = getopts(process.argv.slice(1), {
+ alias: {
+ resultsDir: 'r',
+ precision: 'p'
+ },
+ default: {}
+})
+
+const { generateTable } = require('photofinish')
+
+async function getSpecs () {
+ const cpuInfo = await systemInformation.cpu()
+
+ return {
+ cpu: {
+ brand: cpuInfo.brand,
+ speed: `${cpuInfo.speed} GHz`
+ }
+ }
+}
+
+async function saveTable () {
+ const baseResultsDir = options.resultsDir
+ const benchmarkResults = await loadResults(baseResultsDir)
+
+ const table = generateTable(benchmarkResults, {
+ precision: options.precision,
+ sortBy: [
+ { field: 'meanTimeNs', order: 'asc' }
+ ]
+ })
+
+ const specs = await getSpecs()
+
+ console.log(specs)
+ console.log(table)
+
+ const targetFilePath = path.resolve(baseResultsDir, 'results.md')
+ fs.writeFileSync(
+ targetFilePath,
+ `${table}` +
+ `\n\n**Specs**: ${specs.cpu.brand} (${specs.cpu.speed})`
+ )
+}
+
+saveTable()