diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-21 20:56:19 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-21 20:56:19 +0000 |
commit | 0b6210cd37b68b94252cb798598b12974a20e1c1 (patch) | |
tree | e371686554a877842d95aa94f100bee552ff2a8e /fastify-busboy/benchmarks/busboy | |
parent | Initial commit. (diff) | |
download | node-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/busboy')
-rw-r--r-- | fastify-busboy/benchmarks/busboy/contestants/busboy.js | 40 | ||||
-rw-r--r-- | fastify-busboy/benchmarks/busboy/contestants/fastify-busboy.js | 41 | ||||
-rw-r--r-- | fastify-busboy/benchmarks/busboy/data.js | 34 | ||||
-rw-r--r-- | fastify-busboy/benchmarks/busboy/executioner.js | 50 | ||||
-rw-r--r-- | fastify-busboy/benchmarks/busboy/regenerate.cmd | 17 | ||||
-rw-r--r-- | fastify-busboy/benchmarks/busboy/validator.js | 15 |
6 files changed, 197 insertions, 0 deletions
diff --git a/fastify-busboy/benchmarks/busboy/contestants/busboy.js b/fastify-busboy/benchmarks/busboy/contestants/busboy.js new file mode 100644 index 0000000..6cb3414 --- /dev/null +++ b/fastify-busboy/benchmarks/busboy/contestants/busboy.js @@ -0,0 +1,40 @@ +'use strict' + +const Busboy = require('busboy') +const { buffer, boundary } = require('../data') + +function process () { + const busboy = Busboy({ + headers: { + 'content-type': 'multipart/form-data; boundary=' + boundary + } + }) + let processedData = '' + + return new Promise((resolve, reject) => { + busboy.on('file', (field, file, filename, encoding, mimetype) => { + // console.log('read file') + file.on('data', (data) => { + processedData += data.toString() + // console.log(`File [${filename}] got ${data.length} bytes`); + }) + file.on('end', (fieldname) => { + // console.log(`File [${fieldname}] Finished`); + }) + }) + + busboy.on('error', function (err) { + reject(err) + }) + busboy.on('finish', function () { + resolve(processedData) + }) + busboy.write(buffer, () => { }) + + busboy.end() + }) +} + +module.exports = { + process +} diff --git a/fastify-busboy/benchmarks/busboy/contestants/fastify-busboy.js b/fastify-busboy/benchmarks/busboy/contestants/fastify-busboy.js new file mode 100644 index 0000000..6750f77 --- /dev/null +++ b/fastify-busboy/benchmarks/busboy/contestants/fastify-busboy.js @@ -0,0 +1,41 @@ +'use strict' + +const Busboy = require('../../../lib/main') +const { buffer, boundary } = require('../data') + +function process () { + const busboy = new Busboy({ + headers: { + 'content-type': 'multipart/form-data; boundary=' + boundary + } + }) + + let processedData = '' + + return new Promise((resolve, reject) => { + busboy.on('file', (field, file, filename, encoding, mimetype) => { + // console.log('read file') + file.on('data', (data) => { + processedData += data.toString() + // console.log(`File [${filename}] got ${data.length} bytes`); + }) + file.on('end', (fieldname) => { + // console.log(`File [${fieldname}] Finished`); + }) + }) + + busboy.on('error', function (err) { + reject(err) + }) + busboy.on('finish', function () { + resolve(processedData) + }) + busboy.write(buffer, () => { }) + + busboy.end() + }) +} + +module.exports = { + process +} diff --git a/fastify-busboy/benchmarks/busboy/data.js b/fastify-busboy/benchmarks/busboy/data.js new file mode 100644 index 0000000..4fdefae --- /dev/null +++ b/fastify-busboy/benchmarks/busboy/data.js @@ -0,0 +1,34 @@ +'use strict'
+
+const boundary = '-----------------------------paZqsnEHRufoShdX6fh0lUhXBP4k'
+const randomContent = Buffer.from(makeString(1024 * 500), 'utf8')
+const buffer = createMultipartBuffer(boundary)
+
+function makeString (length) {
+ let result = ''
+ const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
+ const charactersLength = characters.length
+ for (var i = 0; i < length; i++) { // eslint-disable-line no-var
+ result += characters.charAt(Math.floor(Math.random() *
+ charactersLength))
+ }
+ return result
+}
+
+function createMultipartBuffer (boundary) {
+ const payload = [
+ '--' + boundary,
+ 'Content-Disposition: form-data; name="upload_file_0"; filename="1k_a.dat"',
+ 'Content-Type: application/octet-stream',
+ '',
+ randomContent,
+ '--' + boundary + '--'
+ ].join('\r\n')
+ return Buffer.from(payload, 'ascii')
+}
+
+module.exports = {
+ boundary,
+ buffer,
+ randomContent
+}
diff --git a/fastify-busboy/benchmarks/busboy/executioner.js b/fastify-busboy/benchmarks/busboy/executioner.js new file mode 100644 index 0000000..524912c --- /dev/null +++ b/fastify-busboy/benchmarks/busboy/executioner.js @@ -0,0 +1,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() diff --git a/fastify-busboy/benchmarks/busboy/regenerate.cmd b/fastify-busboy/benchmarks/busboy/regenerate.cmd new file mode 100644 index 0000000..87c0768 --- /dev/null +++ b/fastify-busboy/benchmarks/busboy/regenerate.cmd @@ -0,0 +1,17 @@ +rem Make sure to run this in Admin account
+rem
+call npm run install-node
+timeout /t 2
+call nvm use 17.2.0
+timeout /t 2
+call npm run benchmark-all
+call nvm use 16.13.1
+timeout /t 2
+call npm run benchmark-all
+call nvm use 14.18.2
+timeout /t 2
+call npm run benchmark-all
+call nvm use 12.22.7
+timeout /t 2
+call npm run benchmark-all
+call npm run combine-results
diff --git a/fastify-busboy/benchmarks/busboy/validator.js b/fastify-busboy/benchmarks/busboy/validator.js new file mode 100644 index 0000000..a86cc33 --- /dev/null +++ b/fastify-busboy/benchmarks/busboy/validator.js @@ -0,0 +1,15 @@ +'use strict'
+
+const { validateEqual } = require('validation-utils')
+const { randomContent } = require('./data')
+
+const EXPECTED_RESULT = randomContent.toString()
+
+async function validateAccuracy (actualResultPromise) {
+ const result = await actualResultPromise
+ validateEqual(result, EXPECTED_RESULT)
+}
+
+module.exports = {
+ validateAccuracy
+}
|