Skip to content

Commit

Permalink
benchmark: add stream.pipe benchmarks
Browse files Browse the repository at this point in the history
PR-URL: #18617
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: Anatoli Papirovski <[email protected]>
Reviewed-By: Benedikt Meurer <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Tiancheng "Timothy" Gu <[email protected]>
  • 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.