const Benchmark = require('benchmark') const { Writable, Readable, PassThrough } = require('stream'); const suite = new Benchmark.Suite; function devnull() { return new Writable({ objectMode: true, write: function (event, encoding, callback) { callback(); } }) } function readable() { let idx = 0, len = 100; return new Readable({ read: function() { while(idx++ < len) { if(!this.push('foo' + idx)) return; } this.push(null); } }); } console.log(`Node ${process.version}`); // add tests suite .add('read to write', function(deferred) { readable() .pipe(devnull()) .on('finish', () => deferred.resolve()) }, {defer: true}) .add('read to passthru to write', function(deferred) { readable() .pipe(new PassThrough()) .pipe(devnull()) .on('finish', () => deferred.resolve()) }, {defer: true}) // add listeners .on('cycle', function(event) { console.log(String(event.target)); }) // run async .run({ 'async': true });