benchmark: include writev in benchmark

Currently we only consider write when benchmarking.

PR-URL: https://github.com/nodejs/node/pull/31066
Reviewed-By: Denys Otrishko <shishugi@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
This commit is contained in:
Robert Nagy 2019-12-23 11:43:36 +01:00 committed by Ruben Bridgewater
parent 0e21c1e637
commit f68285b098
No known key found for this signature in database
GPG Key ID: F07496B3EB3C1762
2 changed files with 17 additions and 4 deletions

View File

@ -5,25 +5,36 @@ const Writable = require('stream').Writable;
const bench = common.createBenchmark(main, { const bench = common.createBenchmark(main, {
n: [2e6], 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 b = Buffer.allocUnsafe(1024);
const s = new Writable(); const s = new Writable();
sync = sync === 'yes'; sync = sync === 'yes';
s._write = function(chunk, encoding, cb) {
const writecb = (cb) => {
if (sync) if (sync)
cb(); cb();
else else
process.nextTick(cb); 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(); bench.start();
let k = 0; let k = 0;
function run() { function run() {
while (k++ < n && s.write(b)); while (k++ < n && s.write(b, cb));
if (k >= n) if (k >= n)
bench.end(n); bench.end(n);
} }

View File

@ -9,6 +9,8 @@ runBenchmark('streams',
'kind=duplex', 'kind=duplex',
'n=1', 'n=1',
'sync=no', 'sync=no',
'writev=no',
'callback=no',
'type=buffer', 'type=buffer',
], ],
{ NODEJS_BENCHMARK_ZERO_ALLOWED: 1 }); { NODEJS_BENCHMARK_ZERO_ALLOWED: 1 });