Skip to content

Commit

Permalink
benchmark: include writev in benchmark
Browse files Browse the repository at this point in the history
Currently we only consider write when benchmarking.

PR-URL: #31066
Reviewed-By: Denys Otrishko <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
  • Loading branch information
ronag authored and BridgeAR committed Jan 3, 2020
1 parent 647f3c7 commit 01fd3be
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
19 changes: 15 additions & 4 deletions benchmark/streams/writable-manywrites.js
Original file line number Diff line number Diff line change
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
2 changes: 2 additions & 0 deletions test/benchmark/test-benchmark-streams.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ runBenchmark('streams',
'kind=duplex',
'n=1',
'sync=no',
'writev=no',
'callback=no',
'type=buffer',
],
{ NODEJS_BENCHMARK_ZERO_ALLOWED: 1 });

0 comments on commit 01fd3be

Please sign in to comment.