Skip to content
Closed
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 25 additions & 9 deletions benchmark/streams/writable-manywrites.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,41 @@ const Writable = require('stream').Writable;

const bench = common.createBenchmark(main, {
n: [2e6],
sync: ['yes', 'no']
sync: ['yes', 'no'],
writev: ['yes', 'no'],
callback: ['yes', 'no']
});

function main({ n, sync }) {
function nop() {}

function main({ n, sync, writev, callback }) {
const b = Buffer.allocUnsafe(1024);
const s = new Writable();
sync = sync === 'yes';
s._write = function(chunk, encoding, cb) {
if (sync)
cb();
else
process.nextTick(cb);
};

if (writev === 'yes') {
s._writev = function(chunks, cb) {
if (sync)
cb();
else
process.nextTick(cb);
};
} else {
s._write = function(chunk, encoding, cb) {
if (sync)
cb();
else
process.nextTick(cb);
};
}
Comment thread
ronag marked this conversation as resolved.
Resolved

const cb = callback === 'yes' ? nop : null;
Comment thread
ronag marked this conversation as resolved.
Resolved

bench.start();

let k = 0;
function run() {
while (k++ < n && s.write(b));
while (k++ < n && s.write(b, cb));
if (k >= n)
bench.end(n);
}
Expand Down