Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Benchmarks for busboy #40

Merged
merged 3 commits into from
Nov 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .nycrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
"text-summary"
],
"exclude": [
"bench",
"test",
"coverage",
".eslintrc.js",
"deps/dicer/bench"
".eslintrc.js"
],
"check-coverage": true,
"lines": 51,
Expand Down
62 changes: 62 additions & 0 deletions bench/busboy-bench.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
const Busboy = require('busboy');

function createMultipartBuffer(boundary, size) {
const head =
'--' + boundary + '\r\n'
+ 'content-disposition: form-data; name="field1"\r\n'
+ '\r\n'
, tail = '\r\n--' + boundary + '--\r\n'
, buffer = Buffer.allocUnsafe(size);

buffer.write(head, 0, 'ascii');
buffer.write(tail, buffer.length - tail.length, 'ascii');
return buffer;
}

for (let i = 0, il = 10; i < il; i++) {
const boundary = '-----------------------------168072824752491622650073',
d = new Busboy({
headers: {
'content-type': 'multipart/form-data; boundary=' + boundary
}
}),
mb = 100,
buffer = createMultipartBuffer(boundary, mb * 1024 * 1024),
callbacks =
{
partBegin: -1,
partEnd: -1,
headerField: -1,
headerValue: -1,
partData: -1,
end: -1,
};


d.on('part', function (p) {
callbacks.partBegin++;
p.on('header', function (header) {
/*for (var h in header)
console.log('Part header: k: ' + inspect(h) + ', v: ' + inspect(header[h]));*/
});
p.on('data', function (data) {
callbacks.partData++;
//console.log('Part data: ' + inspect(data.toString()));
});
p.on('end', function () {
//console.log('End of part\n');
callbacks.partEnd++;
});
});
d.on('end', function () {
//console.log('End of parts');
callbacks.end++;
});

const start = +new Date();
d.write(buffer);
const duration = +new Date - start;
const mbPerSec = (mb / (duration / 1000)).toFixed(2);

console.log(mbPerSec + ' mb/sec');
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const Dicer = require('../lib/Dicer')
const Dicer = require('../../deps/dicer/lib/Dicer')

function createMultipartBuffer(boundary, size) {
const head =
Expand Down
File renamed without changes.
57 changes: 57 additions & 0 deletions bench/fastify-busboy-bench.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
const Busboy = require('../lib/main');

function createMultipartBuffer(boundary, size) {
const head =
'--' + boundary + '\r\n'
+ 'content-disposition: form-data; name="field1"\r\n'
+ '\r\n'
, tail = '\r\n--' + boundary + '--\r\n'
, buffer = Buffer.allocUnsafe(size);

buffer.write(head, 0, 'ascii');
buffer.write(tail, buffer.length - tail.length, 'ascii');
return buffer;
}

for (let i = 0, il = 10; i < il; i++) {
const boundary = '-----------------------------168072824752491622650073',
d = new Busboy({
headers: {
'content-type': 'multipart/form-data; boundary=' + boundary
}
}),
mb = 100,
buffer = createMultipartBuffer(boundary, mb * 1024 * 1024),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we probably should extract shared part somewhere to reduce risk of benchmarks diverging over time.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For Fastify-Busboy and Old-Busboy?

Copy link
Member

@kibertoad kibertoad Nov 30, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

at the very least, but I assume there is lots of duplication across all benchmarks (which we'll need to revise eventually too).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we do it in another PR? Benchmarks against other Projects has to be any way cleaned up.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure!

callbacks =
{
partBegin: -1,
partEnd: -1,
headerField: -1,
headerValue: -1,
partData: -1,
end: -1,
};


d.on('part', function (p) {
callbacks.partBegin++;
p.on('header', function (header) {
});
p.on('data', function (data) {
callbacks.partData++;
});
p.on('end', function () {
callbacks.partEnd++;
});
});
d.on('end', function () {
callbacks.end++;
});

const start = +new Date();
d.write(buffer);
const duration = +new Date - start;
const mbPerSec = (mb / (duration / 1000)).toFixed(2);

console.log(mbPerSec + ' mb/sec');
}
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"main": "lib/main",
"types": "lib/main.d.ts",
"scripts": {
"bench:dicer": "node deps/dicer/bench/dicer-bench-multipart-parser.js",
"bench:busboy": "node bench/fastify-busboy-bench.js",
"bench:dicer": "node bench/dicer/dicer-bench-multipart-parser.js",
"coveralls": "nyc report --reporter=lcov",
"lint": "eslint .",
"lint:everything": "npm run lint && npm run test:types",
Expand All @@ -33,6 +34,7 @@
},
"devDependencies": {
"@types/node": "^16.11.10",
"busboy": "^0.3.1",
"chai": "^4.3.4",
"eslint": "^8.3.0",
"eslint-plugin-node": "^11.1.0",
Expand Down