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

Function run

benchmark/streams/iter-throughput-broadcast.js:35–63  ·  view source on GitHub ↗
(cb)

Source from the content-addressed store, hash-verified

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();

Callers 3

benchClassicFunction · 0.70
benchWebStreamFunction · 0.70
benchIterFunction · 0.70

Calls 15

teeMethod · 0.80
allMethod · 0.80
writeFunction · 0.70
wsFunction · 0.70
drainFunction · 0.70
mapMethod · 0.65
cbFunction · 0.50
broadcastFunction · 0.50
onMethod · 0.45
pushMethod · 0.45
shiftMethod · 0.45
pipeToMethod · 0.45

Tested by

no test coverage detected