Skip to content
Permalink
Browse files

benchmark: include writev in benchmark

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 BridgeAR committed Dec 23, 2019
1 parent 647f3c7 commit 01fd3be84af93c8e033f8cfd97e23389a5f10b00
Showing with 17 additions and 4 deletions.
  1. +15 −4 benchmark/streams/writable-manywrites.js
  2. +2 −0 test/benchmark/test-benchmark-streams.js
@@ -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);
}
@@ -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.
You can’t perform that action at this time.