11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ciconst common = require('../common.js'); 31cb0ef41Sopenharmony_ciconst { 41cb0ef41Sopenharmony_ci ReadableStream, 51cb0ef41Sopenharmony_ci TransformStream, 61cb0ef41Sopenharmony_ci WritableStream, 71cb0ef41Sopenharmony_ci} = require('node:stream/web'); 81cb0ef41Sopenharmony_ciconst assert = require('assert'); 91cb0ef41Sopenharmony_ci 101cb0ef41Sopenharmony_ciconst bench = common.createBenchmark(main, { 111cb0ef41Sopenharmony_ci n: [50e3], 121cb0ef41Sopenharmony_ci kind: ['ReadableStream', 'TransformStream', 'WritableStream'], 131cb0ef41Sopenharmony_ci}); 141cb0ef41Sopenharmony_ci 151cb0ef41Sopenharmony_cilet rs, ws, ts; 161cb0ef41Sopenharmony_ci 171cb0ef41Sopenharmony_cifunction main({ n, kind }) { 181cb0ef41Sopenharmony_ci switch (kind) { 191cb0ef41Sopenharmony_ci case 'ReadableStream': 201cb0ef41Sopenharmony_ci bench.start(); 211cb0ef41Sopenharmony_ci for (let i = 0; i < n; ++i) 221cb0ef41Sopenharmony_ci rs = new ReadableStream(); 231cb0ef41Sopenharmony_ci bench.end(n); 241cb0ef41Sopenharmony_ci 251cb0ef41Sopenharmony_ci // Avoid V8 deadcode (elimination) 261cb0ef41Sopenharmony_ci assert.ok(rs); 271cb0ef41Sopenharmony_ci break; 281cb0ef41Sopenharmony_ci case 'WritableStream': 291cb0ef41Sopenharmony_ci bench.start(); 301cb0ef41Sopenharmony_ci for (let i = 0; i < n; ++i) 311cb0ef41Sopenharmony_ci ws = new WritableStream(); 321cb0ef41Sopenharmony_ci bench.end(n); 331cb0ef41Sopenharmony_ci 341cb0ef41Sopenharmony_ci // Avoid V8 deadcode (elimination) 351cb0ef41Sopenharmony_ci assert.ok(ws); 361cb0ef41Sopenharmony_ci break; 371cb0ef41Sopenharmony_ci case 'TransformStream': 381cb0ef41Sopenharmony_ci bench.start(); 391cb0ef41Sopenharmony_ci for (let i = 0; i < n; ++i) 401cb0ef41Sopenharmony_ci ts = new TransformStream(); 411cb0ef41Sopenharmony_ci bench.end(n); 421cb0ef41Sopenharmony_ci 431cb0ef41Sopenharmony_ci // Avoid V8 deadcode (elimination) 441cb0ef41Sopenharmony_ci assert.ok(ts); 451cb0ef41Sopenharmony_ci break; 461cb0ef41Sopenharmony_ci default: 471cb0ef41Sopenharmony_ci throw new Error('Invalid kind'); 481cb0ef41Sopenharmony_ci } 491cb0ef41Sopenharmony_ci} 50