Skip to content

Commit d5c0e4d

Browse files
ronagtargos
authored andcommitted
benchmark: include writev in benchmark
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]>
1 parent 86d1998 commit d5c0e4d

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

benchmark/streams/writable-manywrites.js

+15-4
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,36 @@ const Writable = require('stream').Writable;
55

66
const bench = common.createBenchmark(main, {
77
n: [2e6],
8-
sync: ['yes', 'no']
8+
sync: ['yes', 'no'],
9+
writev: ['yes', 'no'],
10+
callback: ['yes', 'no']
911
});
1012

11-
function main({ n, sync }) {
13+
function main({ n, sync, writev, callback }) {
1214
const b = Buffer.allocUnsafe(1024);
1315
const s = new Writable();
1416
sync = sync === 'yes';
15-
s._write = function(chunk, encoding, cb) {
17+
18+
const writecb = (cb) => {
1619
if (sync)
1720
cb();
1821
else
1922
process.nextTick(cb);
2023
};
2124

25+
if (writev === 'yes') {
26+
s._writev = (chunks, cb) => writecb(cb);
27+
} else {
28+
s._write = (chunk, encoding, cb) => writecb(cb);
29+
}
30+
31+
const cb = callback === 'yes' ? () => {} : null;
32+
2233
bench.start();
2334

2435
let k = 0;
2536
function run() {
26-
while (k++ < n && s.write(b));
37+
while (k++ < n && s.write(b, cb));
2738
if (k >= n)
2839
bench.end(n);
2940
}

test/benchmark/test-benchmark-streams.js

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ runBenchmark('streams',
99
'kind=duplex',
1010
'n=1',
1111
'sync=no',
12+
'writev=no',
13+
'callback=no',
1214
'type=buffer',
1315
],
1416
{ NODEJS_BENCHMARK_ZERO_ALLOWED: 1 });

0 commit comments

Comments
 (0)