node/benchmark/webstreams/pipe-to.js
Raz Luvaton 7ad4c0f4a6
benchmark: shorten pipe-to by reducing number of chunks
PR-URL: https://github.com/nodejs/node/pull/49577
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Debadree Chatterjee <debadree333@gmail.com>
2023-09-13 19:44:44 +00:00

37 lines
780 B
JavaScript

'use strict';
const common = require('../common.js');
const {
ReadableStream,
WritableStream,
} = require('node:stream/web');
const bench = common.createBenchmark(main, {
n: [5e5],
highWaterMarkR: [512, 1024, 2048, 4096],
highWaterMarkW: [512, 1024, 2048, 4096],
});
async function main({ n, highWaterMarkR, highWaterMarkW }) {
const b = Buffer.alloc(1024);
let i = 0;
const rs = new ReadableStream({
highWaterMark: highWaterMarkR,
pull: function(controller) {
if (i++ < n) {
controller.enqueue(b);
} else {
controller.close();
}
},
});
const ws = new WritableStream({
highWaterMark: highWaterMarkW,
write(chunk, controller) {},
close() { bench.end(n); },
});
bench.start();
rs.pipeTo(ws);
}