| 33 | |
| 34 | function 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(); |