Skip to content

Commit

Permalink
benchmark: add stream.pipe benchmarks
Browse files Browse the repository at this point in the history
PR-URL: nodejs#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>
  • Loading branch information
mafintosh authored and addaleax committed Feb 27, 2018
1 parent cfb78bc commit be9777c
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
24 changes: 24 additions & 0 deletions benchmark/streams/pipe-object-mode.js
Original file line number Diff line number Diff line change
@@ -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 changes: 24 additions & 0 deletions benchmark/streams/pipe.js
Original file line number Diff line number Diff line change
@@ -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));
}

0 comments on commit be9777c

Please sign in to comment.