11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ciconst common = require('../common.js'); 31cb0ef41Sopenharmony_ciconst { 41cb0ef41Sopenharmony_ci ReadableStream, 51cb0ef41Sopenharmony_ci WritableStream, 61cb0ef41Sopenharmony_ci} = require('node:stream/web'); 71cb0ef41Sopenharmony_ci 81cb0ef41Sopenharmony_ciconst bench = common.createBenchmark(main, { 91cb0ef41Sopenharmony_ci n: [5e6], 101cb0ef41Sopenharmony_ci highWaterMarkR: [512, 1024, 2048, 4096], 111cb0ef41Sopenharmony_ci highWaterMarkW: [512, 1024, 2048, 4096], 121cb0ef41Sopenharmony_ci}); 131cb0ef41Sopenharmony_ci 141cb0ef41Sopenharmony_ci 151cb0ef41Sopenharmony_ciasync function main({ n, highWaterMarkR, highWaterMarkW }) { 161cb0ef41Sopenharmony_ci const b = Buffer.alloc(1024); 171cb0ef41Sopenharmony_ci let i = 0; 181cb0ef41Sopenharmony_ci const rs = new ReadableStream({ 191cb0ef41Sopenharmony_ci highWaterMark: highWaterMarkR, 201cb0ef41Sopenharmony_ci pull: function(controller) { 211cb0ef41Sopenharmony_ci if (i++ === n) { 221cb0ef41Sopenharmony_ci controller.enqueue(b); 231cb0ef41Sopenharmony_ci } else { 241cb0ef41Sopenharmony_ci controller.close(); 251cb0ef41Sopenharmony_ci } 261cb0ef41Sopenharmony_ci }, 271cb0ef41Sopenharmony_ci }); 281cb0ef41Sopenharmony_ci const ws = new WritableStream({ 291cb0ef41Sopenharmony_ci highWaterMark: highWaterMarkW, 301cb0ef41Sopenharmony_ci write(chunk, controller) {}, 311cb0ef41Sopenharmony_ci close() { bench.end(n); }, 321cb0ef41Sopenharmony_ci }); 331cb0ef41Sopenharmony_ci 341cb0ef41Sopenharmony_ci bench.start(); 351cb0ef41Sopenharmony_ci rs.pipeTo(ws); 361cb0ef41Sopenharmony_ci} 37