1'use strict'; 2const common = require('../common.js'); 3const { 4 ReadableStream, 5} = require('node:stream/web'); 6 7const bench = common.createBenchmark(main, { 8 n: [1e5], 9}); 10 11 12async 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} 32