11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ciconst common = require('../common.js'); 41cb0ef41Sopenharmony_ci 51cb0ef41Sopenharmony_ciconst { 61cb0ef41Sopenharmony_ci PerformanceObserver, 71cb0ef41Sopenharmony_ci performance, 81cb0ef41Sopenharmony_ci} = require('perf_hooks'); 91cb0ef41Sopenharmony_ci 101cb0ef41Sopenharmony_cifunction createTimingInfo({ 111cb0ef41Sopenharmony_ci startTime = 0, 121cb0ef41Sopenharmony_ci redirectStartTime = 0, 131cb0ef41Sopenharmony_ci redirectEndTime = 0, 141cb0ef41Sopenharmony_ci postRedirectStartTime = 0, 151cb0ef41Sopenharmony_ci finalServiceWorkerStartTime = 0, 161cb0ef41Sopenharmony_ci finalNetworkRequestStartTime = 0, 171cb0ef41Sopenharmony_ci finalNetworkResponseStartTime = 0, 181cb0ef41Sopenharmony_ci endTime = 0, 191cb0ef41Sopenharmony_ci encodedBodySize = 0, 201cb0ef41Sopenharmony_ci decodedBodySize = 0, 211cb0ef41Sopenharmony_ci finalConnectionTimingInfo = null, 221cb0ef41Sopenharmony_ci}) { 231cb0ef41Sopenharmony_ci if (finalConnectionTimingInfo !== null) { 241cb0ef41Sopenharmony_ci finalConnectionTimingInfo.domainLookupStartTime = 251cb0ef41Sopenharmony_ci finalConnectionTimingInfo.domainLookupStartTime || 0; 261cb0ef41Sopenharmony_ci finalConnectionTimingInfo.domainLookupEndTime = 271cb0ef41Sopenharmony_ci finalConnectionTimingInfo.domainLookupEndTime || 0; 281cb0ef41Sopenharmony_ci finalConnectionTimingInfo.connectionStartTime = 291cb0ef41Sopenharmony_ci finalConnectionTimingInfo.connectionStartTime || 0; 301cb0ef41Sopenharmony_ci finalConnectionTimingInfo.connectionEndTime = 311cb0ef41Sopenharmony_ci finalConnectionTimingInfo.connectionEndTime || 0; 321cb0ef41Sopenharmony_ci finalConnectionTimingInfo.secureConnectionStartTime = 331cb0ef41Sopenharmony_ci finalConnectionTimingInfo.secureConnectionStartTime || 0; 341cb0ef41Sopenharmony_ci finalConnectionTimingInfo.ALPNNegotiatedProtocol = 351cb0ef41Sopenharmony_ci finalConnectionTimingInfo.ALPNNegotiatedProtocol || []; 361cb0ef41Sopenharmony_ci } 371cb0ef41Sopenharmony_ci return { 381cb0ef41Sopenharmony_ci startTime, 391cb0ef41Sopenharmony_ci redirectStartTime, 401cb0ef41Sopenharmony_ci redirectEndTime, 411cb0ef41Sopenharmony_ci postRedirectStartTime, 421cb0ef41Sopenharmony_ci finalServiceWorkerStartTime, 431cb0ef41Sopenharmony_ci finalNetworkRequestStartTime, 441cb0ef41Sopenharmony_ci finalNetworkResponseStartTime, 451cb0ef41Sopenharmony_ci endTime, 461cb0ef41Sopenharmony_ci encodedBodySize, 471cb0ef41Sopenharmony_ci decodedBodySize, 481cb0ef41Sopenharmony_ci finalConnectionTimingInfo, 491cb0ef41Sopenharmony_ci }; 501cb0ef41Sopenharmony_ci} 511cb0ef41Sopenharmony_ci 521cb0ef41Sopenharmony_ciconst bench = common.createBenchmark(main, { 531cb0ef41Sopenharmony_ci n: [1e5], 541cb0ef41Sopenharmony_ci observe: ['resource'], 551cb0ef41Sopenharmony_ci}); 561cb0ef41Sopenharmony_ci 571cb0ef41Sopenharmony_cifunction test() { 581cb0ef41Sopenharmony_ci const timingInfo = createTimingInfo({ finalConnectionTimingInfo: {} }); 591cb0ef41Sopenharmony_ci performance.markResourceTiming( 601cb0ef41Sopenharmony_ci timingInfo, 611cb0ef41Sopenharmony_ci 'http://localhost:8080', 621cb0ef41Sopenharmony_ci 'fetch', 631cb0ef41Sopenharmony_ci {}, 641cb0ef41Sopenharmony_ci '', 651cb0ef41Sopenharmony_ci ); 661cb0ef41Sopenharmony_ci} 671cb0ef41Sopenharmony_ci 681cb0ef41Sopenharmony_cifunction main({ n, observe }) { 691cb0ef41Sopenharmony_ci const obs = new PerformanceObserver(() => { 701cb0ef41Sopenharmony_ci bench.end(n); 711cb0ef41Sopenharmony_ci }); 721cb0ef41Sopenharmony_ci obs.observe({ entryTypes: [observe], buffered: true }); 731cb0ef41Sopenharmony_ci 741cb0ef41Sopenharmony_ci bench.start(); 751cb0ef41Sopenharmony_ci for (let i = 0; i < 1e5; i++) 761cb0ef41Sopenharmony_ci test(); 771cb0ef41Sopenharmony_ci} 78