| 61 | } |
| 62 | |
| 63 | function benchThroughput(n, numberOfPassThroughs, chunks) { |
| 64 | const chunk = Buffer.alloc(1024); |
| 65 | |
| 66 | let i = 0; |
| 67 | bench.start(); |
| 68 | |
| 69 | function run() { |
| 70 | if (i++ === n) { |
| 71 | bench.end(n * chunks); |
| 72 | return; |
| 73 | } |
| 74 | |
| 75 | const passThroughs = []; |
| 76 | for (let i = 0; i < numberOfPassThroughs; i++) { |
| 77 | passThroughs.push(new PassThrough()); |
| 78 | } |
| 79 | |
| 80 | let remaining = chunks; |
| 81 | const composed = compose(...passThroughs); |
| 82 | composed.on('data', () => {}); |
| 83 | composed.on('end', run); |
| 84 | |
| 85 | write(); |
| 86 | |
| 87 | function write() { |
| 88 | while (remaining-- > 0) { |
| 89 | if (!composed.write(chunk)) { |
| 90 | composed.once('drain', write); |
| 91 | return; |
| 92 | } |
| 93 | } |
| 94 | composed.end(); |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | run(); |
| 99 | } |