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>
This commit is contained in:
parent
240f9a20b7
commit
da97a47c44
24
benchmark/streams/pipe-object-mode.js
Normal file
24
benchmark/streams/pipe-object-mode.js
Normal file
@ -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 = {};
|
||||||
|
const r = new Readable({ objectMode: true });
|
||||||
|
const w = new Writable({ objectMode: true });
|
||||||
|
|
||||||
|
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));
|
||||||
|
}
|
24
benchmark/streams/pipe.js
Normal file
24
benchmark/streams/pipe.js
Normal file
@ -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));
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user