diff options
author | Alexander Sulfrian <alexander@sulfrian.net> | 2012-04-25 00:13:37 +0200 |
---|---|---|
committer | Alexander Sulfrian <alexander@sulfrian.net> | 2012-04-25 00:23:26 +0200 |
commit | fdc1028cfd9e6563dbbe950cdd539559ce8d6353 (patch) | |
tree | 4b0ae3791baf59e94767dca01c71fd9828a69798 /emacs.d/lisp/jshint-mode/node_modules/formidable/benchmark | |
parent | 452a858fe4d70ec3521687dcbd1a8270f51b6f37 (diff) | |
download | dotfiles-fdc1028cfd9e6563dbbe950cdd539559ce8d6353.tar.gz dotfiles-fdc1028cfd9e6563dbbe950cdd539559ce8d6353.tar.xz dotfiles-fdc1028cfd9e6563dbbe950cdd539559ce8d6353.zip |
emacs: added some additional modes
Diffstat (limited to 'emacs.d/lisp/jshint-mode/node_modules/formidable/benchmark')
-rw-r--r-- | emacs.d/lisp/jshint-mode/node_modules/formidable/benchmark/bench-multipart-parser.js | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/emacs.d/lisp/jshint-mode/node_modules/formidable/benchmark/bench-multipart-parser.js b/emacs.d/lisp/jshint-mode/node_modules/formidable/benchmark/bench-multipart-parser.js new file mode 100644 index 0000000..bff41f1 --- /dev/null +++ b/emacs.d/lisp/jshint-mode/node_modules/formidable/benchmark/bench-multipart-parser.js @@ -0,0 +1,70 @@ +require('../test/common'); +var multipartParser = require('../lib/multipart_parser'), + MultipartParser = multipartParser.MultipartParser, + parser = new MultipartParser(), + Buffer = require('buffer').Buffer, + boundary = '-----------------------------168072824752491622650073', + mb = 100, + buffer = createMultipartBuffer(boundary, mb * 1024 * 1024), + callbacks = + { partBegin: -1, + partEnd: -1, + headerField: -1, + headerValue: -1, + partData: -1, + end: -1, + }; + + +parser.initWithBoundary(boundary); +parser.onHeaderField = function() { + callbacks.headerField++; +}; + +parser.onHeaderValue = function() { + callbacks.headerValue++; +}; + +parser.onPartBegin = function() { + callbacks.partBegin++; +}; + +parser.onPartData = function() { + callbacks.partData++; +}; + +parser.onPartEnd = function() { + callbacks.partEnd++; +}; + +parser.onEnd = 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 = new Buffer(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]); + } +}); |