({ n })
| 10 | |
| 11 | |
| 12 | async function main({ n }) { |
| 13 | const rs = new ReadableStream({ |
| 14 | pull: function(controller) { |
| 15 | controller.enqueue(1); |
| 16 | }, |
| 17 | }); |
| 18 | |
| 19 | let x = 0; |
| 20 | |
| 21 | bench.start(); |
| 22 | for await (const chunk of rs) { |
| 23 | x += chunk; |
| 24 | if (x > n) { |
| 25 | break; |
| 26 | } |
| 27 | } |
| 28 | // Use x to ensure V8 does not optimize away the loop as a noop. |
| 29 | console.assert(x); |
| 30 | bench.end(n); |
| 31 | } |