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

Function benchWebStream

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

Source from the content-addressed store, hash-verified

54}
55
56function benchWebStream(chunk, datasize, n, totalOps) {
57 async function run() {
58 let remaining = datasize;
59 const rs = new ReadableStream({
60 pull(controller) {
61 if (remaining <= 0) { controller.close(); return; }
62 const size = Math.min(remaining, chunk.length);
63 remaining -= size;
64 controller.enqueue(
65 size === chunk.length ? chunk : chunk.subarray(0, size));
66 },
67 });
68 const ws = new WritableStream({ write() {} });
69 await rs
70 .pipeThrough(new CompressionStream('gzip'))
71 .pipeThrough(new DecompressionStream('gzip'))
72 .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

Used in the wild real call sites across dependent graphs

searching dependent graphs…