diff options
author | Mathias Buus <mathiasbuus@gmail.com> | 2018-02-06 22:48:54 +0100 |
---|---|---|
committer | Matteo Collina <hello@matteocollina.com> | 2018-02-09 09:47:40 +0100 |
commit | da97a47c4406d2c4bc867349dd039d6cc7cdff72 (patch) | |
tree | b2172306b54cb1963f919b7ec8f171e2dae30c41 /benchmark/streams/pipe.js | |
parent | 240f9a20b7ff7edad339fbfae7ff50633a300741 (diff) | |
download | android-node-v8-da97a47c4406d2c4bc867349dd039d6cc7cdff72.tar.gz android-node-v8-da97a47c4406d2c4bc867349dd039d6cc7cdff72.tar.bz2 android-node-v8-da97a47c4406d2c4bc867349dd039d6cc7cdff72.zip |
benchmark: add stream.pipe benchmarks
PR-URL: https://github.com/nodejs/node/pull/18617
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: Benedikt Meurer <benedikt.meurer@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Diffstat (limited to 'benchmark/streams/pipe.js')
-rw-r--r-- | benchmark/streams/pipe.js | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/benchmark/streams/pipe.js b/benchmark/streams/pipe.js new file mode 100644 index 0000000000..a7d67b7d69 --- /dev/null +++ b/benchmark/streams/pipe.js @@ -0,0 +1,24 @@ +'use strict'; + +const common = require('../common'); +const { Readable, Writable } = require('stream'); + +const bench = common.createBenchmark(main, { + n: [5e6] +}); + +function main({ n }) { + const b = new Buffer(1024); + const r = new Readable(); + const w = new Writable(); + + var i = 0; + + r._read = () => r.push(i++ === n ? null : b); + w._write = (data, enc, cb) => cb(); + + bench.start(); + + r.pipe(w); + w.on('finish', () => bench.end(n)); +} |