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/bench/dicer/multipartser-bench-multipart-parser.js | |
parent | Initial commit. (diff) | |
download | node-undici-upstream.tar.xz node-undici-upstream.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 '')
-rw-r--r-- | fastify-busboy/bench/dicer/multipartser-bench-multipart-parser.js | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/fastify-busboy/bench/dicer/multipartser-bench-multipart-parser.js b/fastify-busboy/bench/dicer/multipartser-bench-multipart-parser.js new file mode 100644 index 0000000..40ca00b --- /dev/null +++ b/fastify-busboy/bench/dicer/multipartser-bench-multipart-parser.js @@ -0,0 +1,57 @@ +'use strict' + +var multipartser = require('multipartser'), + boundary = '-----------------------------168072824752491622650073', + parser = multipartser(), + mb = 100, + buffer = createMultipartBuffer(boundary, mb * 1024 * 1024), + callbacks = + { partBegin: -1, + partEnd: -1, + headerField: -1, + headerValue: -1, + partData: -1, + end: -1, + }; + +parser.boundary( boundary ); + +parser.on( 'part', function ( part ) { +}); + +parser.on( 'end', function () { + //console.log( 'completed parsing' ); +}); + +parser.on( 'error', function ( error ) { + console.error( error ); +}); + +var start = +new Date(), + nparsed = parser.data(buffer), + nend = parser.end(), + 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]); + }*/ +}); |