| 31 | } |
| 32 | |
| 33 | function benchClassic(chunk, datasize, n, totalOps) { |
| 34 | function run(cb) { |
| 35 | let remaining = datasize; |
| 36 | const r = new Readable({ |
| 37 | read() { |
| 38 | if (remaining <= 0) { this.push(null); return; } |
| 39 | const size = Math.min(remaining, chunk.length); |
| 40 | remaining -= size; |
| 41 | this.push(size === chunk.length ? chunk : chunk.subarray(0, size)); |
| 42 | }, |
| 43 | }); |
| 44 | const w = new Writable({ write(data, enc, cb) { cb(); } }); |
| 45 | pipeline(r, zlib.createGzip(), zlib.createGunzip(), w, cb); |
| 46 | } |
| 47 | |
| 48 | let i = 0; |
| 49 | bench.start(); |
| 50 | (function next() { |
| 51 | if (i++ >= n) return bench.end(totalOps); |
| 52 | run(next); |
| 53 | })(); |
| 54 | } |
| 55 | |
| 56 | function benchWebStream(chunk, datasize, n, totalOps) { |
| 57 | async function run() { |