| 33 | } |
| 34 | |
| 35 | function benchCreation(n, numberOfPassThroughs) { |
| 36 | const cachedPassThroughs = []; |
| 37 | const cachedReadables = []; |
| 38 | const cachedWritables = []; |
| 39 | |
| 40 | for (let i = 0; i < n; i++) { |
| 41 | const passThroughs = []; |
| 42 | |
| 43 | for (let i = 0; i < numberOfPassThroughs; i++) { |
| 44 | passThroughs.push(new PassThrough()); |
| 45 | } |
| 46 | |
| 47 | const readable = Readable.from(['hello', 'world']); |
| 48 | const writable = new Writable({ objectMode: true, write: (chunk, encoding, cb) => cb() }); |
| 49 | |
| 50 | cachedPassThroughs.push(passThroughs); |
| 51 | cachedReadables.push(readable); |
| 52 | cachedWritables.push(writable); |
| 53 | } |
| 54 | |
| 55 | bench.start(); |
| 56 | for (let i = 0; i < n; i++) { |
| 57 | const composed = compose(cachedReadables[i], ...cachedPassThroughs[i], cachedWritables[i]); |
| 58 | composed.end(); |
| 59 | } |
| 60 | bench.end(n); |
| 61 | } |
| 62 | |
| 63 | function benchThroughput(n, numberOfPassThroughs, chunks) { |
| 64 | const chunk = Buffer.alloc(1024); |