Skip to content

Commit

Permalink
add part count validation
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-smart committed Nov 14, 2023
1 parent b2b9de5 commit f937fc3
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 14 deletions.
4 changes: 2 additions & 2 deletions benchmarks/_results/Busboy_comparison-busboy-Node_20.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
"benchmarkCycles": 500,
"benchmarkCycleSamples": 50,
"warmupCycles": 50,
"meanTimeNs": 271603.6766274161,
"meanTimeMs": 0.2716036766274161
"meanTimeNs": 259789.77117937893,
"meanTimeMs": 0.25978977117937896
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
"benchmarkCycles": 500,
"benchmarkCycleSamples": 50,
"warmupCycles": 50,
"meanTimeNs": 192632.5067214754,
"meanTimeMs": 0.1926325067214754
"meanTimeNs": 188173.65372222223,
"meanTimeMs": 0.18817365372222222
}
4 changes: 2 additions & 2 deletions benchmarks/_results/Busboy_comparison-multipasta-Node_20.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
"benchmarkCycles": 500,
"benchmarkCycleSamples": 50,
"warmupCycles": 50,
"meanTimeNs": 79651.12307008775,
"meanTimeMs": 0.07965112307008775
"meanTimeNs": 67089.49805620349,
"meanTimeMs": 0.0670894980562035
}
6 changes: 3 additions & 3 deletions benchmarks/_results/results.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
| Node | Option | Msecs/op | Ops/sec | V8 |
| ------ | -------------- | -------------- | --------- | --------------------- |
| 20.9.0 | multipasta | 0.079651 msecs | 12554.751 | V8 11.3.244.8-node.16 |
| 20.9.0 | fastify-busboy | 0.192633 msecs | 5191.232 | V8 11.3.244.8-node.16 |
| 20.9.0 | busboy | 0.271604 msecs | 3681.835 | V8 11.3.244.8-node.16 |
| 20.9.0 | multipasta | 0.076734 msecs | 13032.031 | V8 11.3.244.8-node.16 |
| 20.9.0 | fastify-busboy | 0.190665 msecs | 5244.802 | V8 11.3.244.8-node.16 |
| 20.9.0 | busboy | 0.266504 msecs | 3752.289 | V8 11.3.244.8-node.16 |

**Specs**: Core™ i9-9880H (2.3 GHz)
5 changes: 4 additions & 1 deletion benchmarks/busboy/contestants/busboy.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,25 @@ function process () {
}
})
let processedSize = 0
let partCount = 0

return new Promise((resolve, reject) => {
busboy.on('file', (field, file, filename, encoding, mimetype) => {
partCount++
file.on('data', (data) => {
processedSize += data.length
})
})
busboy.on('field', (field, value) => {
processedSize += value.length
partCount++
})

busboy.on('error', function (err) {
reject(err)
})
busboy.on('finish', function () {
resolve(processedSize)
resolve([processedSize, partCount])
})
for (const buffer of buffers) { busboy.write(buffer, () => { }) }

Expand Down
5 changes: 4 additions & 1 deletion benchmarks/busboy/contestants/fastify-busboy.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,25 @@ function process () {
})

let processedSize = 0
let partCount = 0

return new Promise((resolve, reject) => {
busboy.on('file', (field, file, filename, encoding, mimetype) => {
partCount++
file.on('data', (data) => {
processedSize += data.length
})
})
busboy.on('field', (field, value) => {
processedSize += value.length
partCount++
})

busboy.on('error', function (err) {
reject(err)
})
busboy.on('finish', function () {
resolve(processedSize)
resolve([processedSize, partCount])
})

for (const buffer of buffers) { busboy.write(buffer, () => { }) }
Expand Down
5 changes: 4 additions & 1 deletion benchmarks/busboy/contestants/multipasta.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@ const { buffers, boundary } = require('../data')
function process () {
return new Promise((resolve, reject) => {
let processedSize = 0
let partCount = 0
const parser = MP.make({
headers: {
'content-type': 'multipart/form-data; boundary=' + boundary
},
onField (_info, value) {
processedSize += value.length
partCount++
},
onFile (_info) {
partCount++
return function (chunk) {
if (chunk !== null) {
processedSize += chunk.length
Expand All @@ -24,7 +27,7 @@ function process () {
reject(err)
},
onDone () {
resolve(processedSize)
resolve([processedSize, partCount])
}
})
for (const buffer of buffers) { parser.write(buffer) }
Expand Down
3 changes: 2 additions & 1 deletion benchmarks/busboy/validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ const { fileContent, fileCount, fieldContent, fieldCount } = require('./data')
const EXPECTED_RESULT = (fileContent.length * fileCount) + (fieldContent.length * fieldCount)

async function validateAccuracy (actualResultPromise) {
const result = await actualResultPromise
const [result, parts] = await actualResultPromise
validateEqual(result, EXPECTED_RESULT)
validateEqual(parts, fileCount + fieldCount)
}

module.exports = {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"devDependencies": {
"@types/node": "^20.1.0",
"busboy": "^1.0.0",
"multipasta": "^0.1.12",
"multipasta": "^0.1.15",
"photofinish": "^1.8.0",
"snazzy": "^9.0.0",
"standard": "^17.0.0",
Expand Down

0 comments on commit f937fc3

Please sign in to comment.