summaryrefslogtreecommitdiffstats
path: root/fastify-busboy/bench/dicer/parted-bench-multipart-parser.js
diff options
context:
space:
mode:
Diffstat (limited to 'fastify-busboy/bench/dicer/parted-bench-multipart-parser.js')
-rw-r--r--fastify-busboy/bench/dicer/parted-bench-multipart-parser.js65
1 files changed, 65 insertions, 0 deletions
diff --git a/fastify-busboy/bench/dicer/parted-bench-multipart-parser.js b/fastify-busboy/bench/dicer/parted-bench-multipart-parser.js
new file mode 100644
index 0000000..e0a4670
--- /dev/null
+++ b/fastify-busboy/bench/dicer/parted-bench-multipart-parser.js
@@ -0,0 +1,65 @@
+'use strict'
+
+// A special, edited version of the multipart parser from parted is needed here
+// because otherwise it attempts to do some things above and beyond just parsing
+// -- like saving to disk and whatnot
+
+var assert = require('node:assert');
+var Parser = require('./parted-multipart'),
+ boundary = '-----------------------------168072824752491622650073',
+ parser = new Parser('boundary=' + boundary),
+ mb = 100,
+ buffer = createMultipartBuffer(boundary, mb * 1024 * 1024),
+ callbacks =
+ { partBegin: -1,
+ partEnd: -1,
+ headerField: -1,
+ headerValue: -1,
+ partData: -1,
+ end: -1,
+ };
+
+
+parser.on('header', function() {
+ //callbacks.headerField++;
+});
+
+parser.on('data', function() {
+ //callbacks.partBegin++;
+});
+
+parser.on('part', function() {
+
+});
+
+parser.on('end', function() {
+ //callbacks.end++;
+});
+
+var start = +new Date(),
+ nparsed = parser.write(buffer),
+ duration = +new Date - start,
+ mbPerSec = (mb / (duration / 1000)).toFixed(2);
+
+console.log(mbPerSec+' mb/sec');
+
+//assert.equal(nparsed, buffer.length);
+
+function createMultipartBuffer(boundary, size) {
+ var 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, 'ascii', 0);
+ buffer.write(tail, 'ascii', buffer.length - tail.length);
+ return buffer;
+}
+
+process.on('exit', function() {
+ /*for (var k in callbacks) {
+ assert.equal(0, callbacks[k], k+' count off by '+callbacks[k]);
+ }*/
+});