Skip to content

Commit 4763ecc

Browse files
committed
add part count validation
1 parent b2b9de5 commit 4763ecc

File tree

9 files changed

+24
-14
lines changed

9 files changed

+24
-14
lines changed

benchmarks/_results/Busboy_comparison-busboy-Node_20.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
"benchmarkCycles": 500,
66
"benchmarkCycleSamples": 50,
77
"warmupCycles": 50,
8-
"meanTimeNs": 271603.6766274161,
9-
"meanTimeMs": 0.2716036766274161
8+
"meanTimeNs": 259789.77117937893,
9+
"meanTimeMs": 0.25978977117937896
1010
}

benchmarks/_results/Busboy_comparison-fastify-busboy-Node_20.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
"benchmarkCycles": 500,
66
"benchmarkCycleSamples": 50,
77
"warmupCycles": 50,
8-
"meanTimeNs": 192632.5067214754,
9-
"meanTimeMs": 0.1926325067214754
8+
"meanTimeNs": 188173.65372222223,
9+
"meanTimeMs": 0.18817365372222222
1010
}

benchmarks/_results/Busboy_comparison-multipasta-Node_20.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
"benchmarkCycles": 500,
66
"benchmarkCycleSamples": 50,
77
"warmupCycles": 50,
8-
"meanTimeNs": 79651.12307008775,
9-
"meanTimeMs": 0.07965112307008775
8+
"meanTimeNs": 67089.49805620349,
9+
"meanTimeMs": 0.0670894980562035
1010
}

benchmarks/_results/results.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
| Node | Option | Msecs/op | Ops/sec | V8 |
22
| ------ | -------------- | -------------- | --------- | --------------------- |
3-
| 20.9.0 | multipasta | 0.079651 msecs | 12554.751 | V8 11.3.244.8-node.16 |
4-
| 20.9.0 | fastify-busboy | 0.192633 msecs | 5191.232 | V8 11.3.244.8-node.16 |
5-
| 20.9.0 | busboy | 0.271604 msecs | 3681.835 | V8 11.3.244.8-node.16 |
3+
| 20.9.0 | multipasta | 0.067089 msecs | 14905.463 | V8 11.3.244.8-node.16 |
4+
| 20.9.0 | fastify-busboy | 0.188174 msecs | 5314.240 | V8 11.3.244.8-node.16 |
5+
| 20.9.0 | busboy | 0.259790 msecs | 3849.266 | V8 11.3.244.8-node.16 |
66

77
**Specs**: Core™ i9-9880H (2.3 GHz)

benchmarks/busboy/contestants/busboy.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,25 @@ function process () {
1010
}
1111
})
1212
let processedSize = 0
13+
let partCount = 0
1314

1415
return new Promise((resolve, reject) => {
1516
busboy.on('file', (field, file, filename, encoding, mimetype) => {
17+
partCount++
1618
file.on('data', (data) => {
1719
processedSize += data.length
1820
})
1921
})
2022
busboy.on('field', (field, value) => {
2123
processedSize += value.length
24+
partCount++
2225
})
2326

2427
busboy.on('error', function (err) {
2528
reject(err)
2629
})
2730
busboy.on('finish', function () {
28-
resolve(processedSize)
31+
resolve([processedSize, partCount])
2932
})
3033
for (const buffer of buffers) { busboy.write(buffer, () => { }) }
3134

benchmarks/busboy/contestants/fastify-busboy.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,25 @@ function process () {
1111
})
1212

1313
let processedSize = 0
14+
let partCount = 0
1415

1516
return new Promise((resolve, reject) => {
1617
busboy.on('file', (field, file, filename, encoding, mimetype) => {
18+
partCount++
1719
file.on('data', (data) => {
1820
processedSize += data.length
1921
})
2022
})
2123
busboy.on('field', (field, value) => {
2224
processedSize += value.length
25+
partCount++
2326
})
2427

2528
busboy.on('error', function (err) {
2629
reject(err)
2730
})
2831
busboy.on('finish', function () {
29-
resolve(processedSize)
32+
resolve([processedSize, partCount])
3033
})
3134

3235
for (const buffer of buffers) { busboy.write(buffer, () => { }) }

benchmarks/busboy/contestants/multipasta.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,17 @@ const { buffers, boundary } = require('../data')
66
function process () {
77
return new Promise((resolve, reject) => {
88
let processedSize = 0
9+
let partCount = 0
910
const parser = MP.make({
1011
headers: {
1112
'content-type': 'multipart/form-data; boundary=' + boundary
1213
},
1314
onField (_info, value) {
1415
processedSize += value.length
16+
partCount++
1517
},
1618
onFile (_info) {
19+
partCount++
1720
return function (chunk) {
1821
if (chunk !== null) {
1922
processedSize += chunk.length
@@ -24,7 +27,7 @@ function process () {
2427
reject(err)
2528
},
2629
onDone () {
27-
resolve(processedSize)
30+
resolve([processedSize, partCount])
2831
}
2932
})
3033
for (const buffer of buffers) { parser.write(buffer) }

benchmarks/busboy/validator.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ const { fileContent, fileCount, fieldContent, fieldCount } = require('./data')
66
const EXPECTED_RESULT = (fileContent.length * fileCount) + (fieldContent.length * fieldCount)
77

88
async function validateAccuracy (actualResultPromise) {
9-
const result = await actualResultPromise
9+
const [result, parts] = await actualResultPromise
1010
validateEqual(result, EXPECTED_RESULT)
11+
validateEqual(parts, fileCount + fieldCount)
1112
}
1213

1314
module.exports = {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"devDependencies": {
3939
"@types/node": "^20.1.0",
4040
"busboy": "^1.0.0",
41-
"multipasta": "^0.1.12",
41+
"multipasta": "^0.1.15",
4242
"photofinish": "^1.8.0",
4343
"snazzy": "^9.0.0",
4444
"standard": "^17.0.0",

0 commit comments

Comments
 (0)