11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ciconst common = require('../common.js'); 31cb0ef41Sopenharmony_ciconst { 41cb0ef41Sopenharmony_ci ReadableStream, 51cb0ef41Sopenharmony_ci} = require('node:stream/web'); 61cb0ef41Sopenharmony_ci 71cb0ef41Sopenharmony_ciconst bench = common.createBenchmark(main, { 81cb0ef41Sopenharmony_ci n: [1e5], 91cb0ef41Sopenharmony_ci}); 101cb0ef41Sopenharmony_ci 111cb0ef41Sopenharmony_ci 121cb0ef41Sopenharmony_ciasync function main({ n }) { 131cb0ef41Sopenharmony_ci const rs = new ReadableStream({ 141cb0ef41Sopenharmony_ci pull: function(controller) { 151cb0ef41Sopenharmony_ci controller.enqueue(1); 161cb0ef41Sopenharmony_ci }, 171cb0ef41Sopenharmony_ci }); 181cb0ef41Sopenharmony_ci 191cb0ef41Sopenharmony_ci let x = 0; 201cb0ef41Sopenharmony_ci 211cb0ef41Sopenharmony_ci bench.start(); 221cb0ef41Sopenharmony_ci for await (const chunk of rs) { 231cb0ef41Sopenharmony_ci x += chunk; 241cb0ef41Sopenharmony_ci if (x > n) { 251cb0ef41Sopenharmony_ci break; 261cb0ef41Sopenharmony_ci } 271cb0ef41Sopenharmony_ci } 281cb0ef41Sopenharmony_ci // Use x to ensure V8 does not optimize away the loop as a noop. 291cb0ef41Sopenharmony_ci console.assert(x); 301cb0ef41Sopenharmony_ci bench.end(n); 311cb0ef41Sopenharmony_ci} 32