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 <shishugi@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
  • Loading branch information
ronag authored and BethGriggs committed Feb 6, 2020
1 parent 76eaf24 commit 471c59b
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
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
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 471c59b

Please sign in to comment.