| 54 | } |
| 55 | |
| 56 | function benchWebStream(chunk, datasize, n, totalOps) { |
| 57 | async function run() { |
| 58 | let remaining = datasize; |
| 59 | const rs = new ReadableStream({ |
| 60 | pull(controller) { |
| 61 | if (remaining <= 0) { controller.close(); return; } |
| 62 | const size = Math.min(remaining, chunk.length); |
| 63 | remaining -= size; |
| 64 | controller.enqueue( |
| 65 | size === chunk.length ? chunk : chunk.subarray(0, size)); |
| 66 | }, |
| 67 | }); |
| 68 | const ws = new WritableStream({ write() {} }); |
| 69 | await rs |
| 70 | .pipeThrough(new CompressionStream('gzip')) |
| 71 | .pipeThrough(new DecompressionStream('gzip')) |
| 72 | .pipeTo(ws); |
| 73 | } |
| 74 | |
| 75 | (async () => { |
| 76 | bench.start(); |
| 77 | for (let i = 0; i < n; i++) await run(); |
| 78 | bench.end(totalOps); |
| 79 | })(); |
| 80 | } |
| 81 | |
| 82 | function benchIter(chunk, datasize, n, totalOps) { |
| 83 | const { pipeTo } = require('stream/iter'); |