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

Function benchClassic

benchmark/streams/iter-throughput-broadcast.js:34–71  ·  view source on GitHub ↗
(chunk, numConsumers, datasize, n, totalOps)

Source from the content-addressed store, hash-verified

32}
33
34function benchClassic(chunk, numConsumers, datasize, n, totalOps) {
35 function run(cb) {
36 const source = new PassThrough();
37 const sinks = [];
38 let finished = 0;
39
40 for (let c = 0; c < numConsumers; c++) {
41 const w = new Writable({ write(data, enc, cb) { cb(); } });
42 source.pipe(w);
43 w.on('finish', () => { if (++finished === numConsumers) cb(); });
44 sinks.push(w);
45 }
46
47 let remaining = datasize;
48 function write() {
49 let ok = true;
50 while (ok && remaining > 0) {
51 const size = Math.min(remaining, chunk.length);
52 remaining -= size;
53 const buf = size === chunk.length ? chunk : chunk.subarray(0, size);
54 ok = source.write(buf);
55 }
56 if (remaining > 0) {
57 source.once('drain', write);
58 } else {
59 source.end();
60 }
61 }
62 write();
63 }
64
65 let i = 0;
66 bench.start();
67 (function next() {
68 if (i++ >= n) return bench.end(totalOps);
69 run(next);
70 })();
71}
72
73function benchWebStream(chunk, numConsumers, datasize, n, totalOps) {
74 async function run() {

Callers 1

mainFunction · 0.70

Calls 3

runFunction · 0.70
startMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected