11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ciconst common = require('../common.js'); 31cb0ef41Sopenharmony_ci 41cb0ef41Sopenharmony_ciconst bench = common.createBenchmark(main, { 51cb0ef41Sopenharmony_ci withBase: ['true', 'false'], 61cb0ef41Sopenharmony_ci type: ['wpt'], // Too many combinations - just use WPT by default 71cb0ef41Sopenharmony_ci e: [1], 81cb0ef41Sopenharmony_ci prop: ['href', 'origin', 'protocol', 91cb0ef41Sopenharmony_ci 'username', 'password', 'host', 'hostname', 'port', 101cb0ef41Sopenharmony_ci 'pathname', 'search', 'searchParams', 'hash'], 111cb0ef41Sopenharmony_ci}); 121cb0ef41Sopenharmony_ci 131cb0ef41Sopenharmony_cifunction setAndGet(data, prop) { 141cb0ef41Sopenharmony_ci const len = data.length; 151cb0ef41Sopenharmony_ci let result = data[0][prop]; 161cb0ef41Sopenharmony_ci bench.start(); 171cb0ef41Sopenharmony_ci for (let i = 0; i < len; ++i) { 181cb0ef41Sopenharmony_ci result = data[i][prop]; 191cb0ef41Sopenharmony_ci data[i][prop] = result; 201cb0ef41Sopenharmony_ci } 211cb0ef41Sopenharmony_ci bench.end(len); 221cb0ef41Sopenharmony_ci return result; 231cb0ef41Sopenharmony_ci} 241cb0ef41Sopenharmony_ci 251cb0ef41Sopenharmony_cifunction get(data, prop) { 261cb0ef41Sopenharmony_ci const len = data.length; 271cb0ef41Sopenharmony_ci let result = data[0][prop]; 281cb0ef41Sopenharmony_ci bench.start(); 291cb0ef41Sopenharmony_ci for (let i = 0; i < len; ++i) { 301cb0ef41Sopenharmony_ci result = data[i][prop]; // get 311cb0ef41Sopenharmony_ci } 321cb0ef41Sopenharmony_ci bench.end(len); 331cb0ef41Sopenharmony_ci return result; 341cb0ef41Sopenharmony_ci} 351cb0ef41Sopenharmony_ci 361cb0ef41Sopenharmony_cifunction main({ e, type, prop, withBase }) { 371cb0ef41Sopenharmony_ci withBase = withBase === 'true'; 381cb0ef41Sopenharmony_ci const data = common.bakeUrlData(type, e, withBase, true); 391cb0ef41Sopenharmony_ci switch (prop) { 401cb0ef41Sopenharmony_ci case 'protocol': 411cb0ef41Sopenharmony_ci case 'username': 421cb0ef41Sopenharmony_ci case 'password': 431cb0ef41Sopenharmony_ci case 'host': 441cb0ef41Sopenharmony_ci case 'hostname': 451cb0ef41Sopenharmony_ci case 'port': 461cb0ef41Sopenharmony_ci case 'pathname': 471cb0ef41Sopenharmony_ci case 'search': 481cb0ef41Sopenharmony_ci case 'hash': 491cb0ef41Sopenharmony_ci case 'href': 501cb0ef41Sopenharmony_ci setAndGet(data, prop); 511cb0ef41Sopenharmony_ci break; 521cb0ef41Sopenharmony_ci case 'origin': 531cb0ef41Sopenharmony_ci case 'searchParams': 541cb0ef41Sopenharmony_ci get(data, prop); 551cb0ef41Sopenharmony_ci break; 561cb0ef41Sopenharmony_ci default: 571cb0ef41Sopenharmony_ci throw new Error('Unknown prop'); 581cb0ef41Sopenharmony_ci } 591cb0ef41Sopenharmony_ci} 60