MCPcopy Create free account
hub / github.com/nodejs/node / benchWebStream

Function benchWebStream

benchmark/streams/iter-throughput-pipeto.js:59–80  ·  view source on GitHub ↗
(chunk, datasize, n, totalOps)

Source from the content-addressed store, hash-verified

57}
58
59function benchWebStream(chunk, datasize, n, totalOps) {
60 async function run() {
61 let remaining = datasize;
62 const rs = new ReadableStream({
63 pull(controller) {
64 if (remaining <= 0) { controller.close(); return; }
65 const size = Math.min(remaining, chunk.length);
66 remaining -= size;
67 controller.enqueue(
68 size === chunk.length ? chunk : chunk.subarray(0, size));
69 },
70 });
71 const ws = new WritableStream({ write() {} });
72 await rs.pipeTo(ws);
73 }
74
75 (async () => {
76 bench.start();
77 for (let i = 0; i < n; i++) await run();
78 bench.end(totalOps);
79 })();
80}
81
82function benchIter(chunk, datasize, n, totalOps) {
83 const { pipeTo } = require('stream/iter');

Callers 1

mainFunction · 0.70

Calls 3

runFunction · 0.70
startMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected