Skip to content

Commit

Permalink
benchmark: add stream.pipe benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
mafintosh committed Feb 7, 2018
1 parent 56990e1 commit 213a5ab
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 213a5ab

Please sign in to comment.