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 4 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
19 changes: 15 additions & 4 deletions benchmark/streams/writable-manywrites.js
Expand Up @@ -5,25 +5,36 @@ 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 main({ n, sync, writev, callback }) {
const b = Buffer.allocUnsafe(1024);
const s = new Writable();
sync = sync === 'yes';
s._write = function(chunk, encoding, cb) {

const writecb = (cb) => {
if (sync)
cb();
else
process.nextTick(cb);
};

if (writev === 'yes') {
s._writev = (chunks, cb) => writecb(cb);
} else {
s._write = (chunk, encoding, cb) => writecb(cb);
}

const cb = callback === 'yes' ? () => {} : null;

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