MCPcopy Index your code
hub / github.com/nodejs/node / benchWebStream

Function benchWebStream

benchmark/streams/iter-throughput-transform.js:69–95  ·  view source on GitHub ↗
(chunk, datasize, n, totalOps)

Source from the content-addressed store, hash-verified

67}
68
69function benchWebStream(chunk, datasize, n, totalOps) {
70 async function run() {
71 let remaining = datasize;
72 const rs = new ReadableStream({
73 pull(controller) {
74 if (remaining <= 0) { controller.close(); return; }
75 const size = Math.min(remaining, chunk.length);
76 remaining -= size;
77 controller.enqueue(
78 size === chunk.length ? chunk : chunk.subarray(0, size));
79 },
80 });
81 const ts = new TransformStream({
82 transform(c, controller) {
83 controller.enqueue(copyBuf(c));
84 },
85 });
86 const ws = new WritableStream({ write() {} });
87 await rs.pipeThrough(ts).pipeTo(ws);
88 }
89
90 (async () => {
91 bench.start();
92 for (let i = 0; i < n; i++) await run();
93 bench.end(totalOps);
94 })();
95}
96
97function benchIter(chunk, datasize, n, totalOps) {
98 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

Used in the wild real call sites across dependent graphs

searching dependent graphs…