Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

benchmark: include writev & callback in benchmark #31066

Closed
wants to merge 5 commits into from
Closed
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 25 additions & 9 deletions benchmark/streams/writable-manywrites.js
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);
};
}
ronag marked this conversation as resolved.
Show resolved Hide resolved

const cb = callback === 'yes' ? nop : null;
ronag marked this conversation as resolved.
Show resolved Hide 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