From f68285b098e6a132af67c82965f8088fd8c6f302 Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Mon, 23 Dec 2019 11:43:36 +0100 Subject: [PATCH] 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 Reviewed-By: Anna Henningsen Reviewed-By: Ruben Bridgewater --- benchmark/streams/writable-manywrites.js | 19 +++++++++++++++---- test/benchmark/test-benchmark-streams.js | 2 ++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/benchmark/streams/writable-manywrites.js b/benchmark/streams/writable-manywrites.js index ebd83779b76158..049bf8eb281db2 100644 --- a/benchmark/streams/writable-manywrites.js +++ b/benchmark/streams/writable-manywrites.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); } diff --git a/test/benchmark/test-benchmark-streams.js b/test/benchmark/test-benchmark-streams.js index 51cdace5748fa4..fa61b8dc4e0ae7 100644 --- a/test/benchmark/test-benchmark-streams.js +++ b/test/benchmark/test-benchmark-streams.js @@ -9,6 +9,8 @@ runBenchmark('streams', 'kind=duplex', 'n=1', 'sync=no', + 'writev=no', + 'callback=no', 'type=buffer', ], { NODEJS_BENCHMARK_ZERO_ALLOWED: 1 });