摘要:高標(biāo)準(zhǔn)精度時(shí)間規(guī)范定義了接口,支持應(yīng)用程序內(nèi)的客戶端延遲測(cè)量。單位是毫秒,精確到微秒,如果因?yàn)橛布蜍浖南拗?,不能精確到微秒,則會(huì)顯示精確到。對(duì)象標(biāo)識(shí)符,不需要唯一。該對(duì)象表示的接口的類型。該性能度量的第一個(gè)記錄時(shí)間戳的時(shí)間值。
高標(biāo)準(zhǔn)精度時(shí)間(High Resolution Time)規(guī)范定義了Performance接口,支持應(yīng)用程序(applications)內(nèi)的客戶端延遲測(cè)量。
Date 對(duì)象表示自1970-01-01起的毫秒精度時(shí)間。在實(shí)踐中,會(huì)受制于時(shí)鐘偏移(clock skew)和系統(tǒng)時(shí)鐘調(diào)整(adjustment of the system clock),所以時(shí)間值可能不能保證一直是在增加的,例如:
var mark_start = Date.now(); doTask(); // Some task var duration = Date.now() - mark_start;
duration 可能 >0,<0,=0。
對(duì)一些需要計(jì)算網(wǎng)頁(yè)加載時(shí)間、腳本執(zhí)行時(shí)間、動(dòng)畫(huà)時(shí)間或是需要更高精確度等情況就不太夠了。
為了保證單調(diào)增長(zhǎng)(monotonically increasing)且更高精確度的時(shí)間值,Performace 接口定義了 DOMHighResTimeStamp 類型,performance.now 方法,performance.timeOrigin 屬性。
單位是毫秒,精確到5微秒(0.005 ms),如果因?yàn)橛布蜍浖南拗疲?User Agent 不能精確到微秒,則會(huì)顯示精確到1ms。
typedef double DOMHighResTimeStamp;Time Origin
計(jì)算時(shí)間的起始點(diǎn),
The time origin is the time value from which time is measured:
If the global object is a Window object, the time origin MUST be equal to:
the time when the browsing context(瀏覽上下文) is first created if there is no previous document;(注:在一個(gè) Web 瀏覽器內(nèi),一個(gè)標(biāo)簽頁(yè)或窗口常包含一個(gè)瀏覽上下文,如一個(gè) iframe 或一個(gè) frameset 內(nèi)的若干 frame。)
otherwise, the time of the user confirming the navigation during the previous document"s prompt to unload algorithm, if a previous document exists and if the confirmation dialog was displayed;
otherwise, the time of starting the navigation responsible for loading the Window object"s newest Document object.
If the global object is a WorkerGlobalScope object, the time origin MUST be equal to the official moment of creation of the worker.
Otherwise, the time origin is undefined.
在 Chrome DevTools 控制臺(tái)打印 performance:
{ navigation: {type: 0, redirectCount: 0} timeOrigin: 1555386564177.783 timing: { connectEnd: 1555386564181 connectStart: 1555386564181 domComplete: 1555386564345 domContentLoadedEventEnd: 1555386564322 domContentLoadedEventStart: 1555386564318 domInteractive: 1555386564317 domLoading: 1555386564286 domainLookupEnd: 1555386564181 domainLookupStart: 1555386564181 fetchStart: 1555386564181 loadEventEnd: 1555386564345 loadEventStart: 1555386564345 navigationStart: 1555386564177 redirectEnd: 0 redirectStart: 0 requestStart: 1555386564181 responseEnd: 1555386564291 responseStart: 1555386564181 secureConnectionStart: 0 unloadEventEnd: 0 unloadEventStart: 0 } }Performance 接口
[Exposed=(Window,Worker)] interface Performance : EventTarget { clearMarks: ? clearMarks() clearMeasures: ? clearMeasures() void clearResourceTimings(); PerformanceEntryList getEntries(); PerformanceEntryList getEntriesByType(DOMString type); PerformanceEntryList getEntriesByName(DOMString name, optional DOMString type); mark: ? mark() measure: ? measure() memory: (...) readonly attribute PerformanceNavigation navigation; DOMHighResTimeStamp now(); attribute EventHandler onresourcetimingbufferfull; void setResourceTimingBufferSize(unsigned long maxSize); readonly attribute DOMHighResTimeStamp timeOrigin; readonly attribute PerformanceTiming timing; [Default] object toJSON(); };performance 屬性
partial interface WindowOrWorkerGlobalScope { [Replaceable] readonly attribute Performance performance; };
例如 window.performance,
interface Performance { readonly attribute PerformanceTiming timing; readonly attribute PerformanceNavigation navigation; }; partial interface Window { [Replaceable] readonly attribute Performance performance; };PerformanceTiming 接口
interface PerformanceTiming { readonly attribute unsigned long long navigationStart; readonly attribute unsigned long long unloadEventStart; readonly attribute unsigned long long unloadEventEnd; readonly attribute unsigned long long redirectStart; readonly attribute unsigned long long redirectEnd; readonly attribute unsigned long long fetchStart; readonly attribute unsigned long long domainLookupStart; readonly attribute unsigned long long domainLookupEnd; readonly attribute unsigned long long connectStart; readonly attribute unsigned long long connectEnd; readonly attribute unsigned long long secureConnectionStart; readonly attribute unsigned long long requestStart; readonly attribute unsigned long long responseStart; readonly attribute unsigned long long responseEnd; readonly attribute unsigned long long domLoading; readonly attribute unsigned long long domInteractive; readonly attribute unsigned long long domContentLoadedEventStart; readonly attribute unsigned long long domContentLoadedEventEnd; readonly attribute unsigned long long domComplete; readonly attribute unsigned long long loadEventStart; readonly attribute unsigned long long loadEventEnd; };
DNS解析:timing.domainLookupEnd - timing.domainLookupStart
建立連接:timing.connectEnd - timing.connectStart
發(fā)送請(qǐng)求:timing.responseStart - timing.requestStart
接收請(qǐng)求:timing.responseEnd - timing.responseStart
解析DOM樹(shù):timing.domInteractive - timing.domLoading
頁(yè)面加載完成:timing.domContentLoadedEventStart - timing.domInteractive
DOMContentLoaded事件耗時(shí):
timing.domContentLoadedEventEnd - timing.domContentLoadedEventStart
DOM加載完成:timing.domComplete - timing.domContentLoadedEventEnd
DOMLoad事件耗時(shí):timing.loadEventEnd - timing.loadEventStart
PerformanceNavigation 接口interface PerformanceNavigation { const unsigned short TYPE_NAVIGATE = 0; const unsigned short TYPE_RELOAD = 1; const unsigned short TYPE_BACK_FORWARD = 2; const unsigned short TYPE_RESERVED = 255; readonly attribute unsigned short type; readonly attribute unsigned short redirectCount; };
TYPE_NAVIGATE (0)
通過(guò)點(diǎn)擊鏈接、書(shū)簽、表單提交、腳本、瀏覽器地址欄輸入地址訪問(wèn)
The page was accessed by following a link, a bookmark, a form submission, or a script, or by typing the URL in the address bar.
TYPE_RELOAD (1)
通過(guò)點(diǎn)擊刷新按鈕或是Location.reload()訪問(wèn)
The page was accessed by clicking the Reload button or via the Location.reload() method.
TYPE_BACK_FORWARD (2)
通過(guò)頁(yè)面前進(jìn)后退訪問(wèn)
The page was accessed by navigating into the history.
TYPE_RESERVED (255)
其他方式
Any other way.
PerformanceEntry 對(duì)象封裝了作為性能時(shí)間線(performance timeline)一部分的單個(gè)性能指標(biāo)。
[Exposed=(Window,Worker)] interface PerformanceEntry { readonly attribute DOMString name; readonly attribute DOMString entryType; readonly attribute DOMHighResTimeStamp startTime; readonly attribute DOMHighResTimeStamp duration; [Default] object toJSON(); };
partial interface Performance { PerformanceEntryList getEntries (); PerformanceEntryList getEntriesByType (DOMString type); PerformanceEntryList getEntriesByName (DOMString name, optional DOMString type); }; typedef sequencePerformanceEntryList;
name:PerformanceEntry 對(duì)象標(biāo)識(shí)符,不需要唯一(unique)。
entryType:該 PerformanceEntry 對(duì)象表示的接口的類型。
startTime:該性能度量的第一個(gè)記錄時(shí)間戳的時(shí)間值。
duration:記錄時(shí)間,即記錄開(kāi)始到結(jié)束的時(shí)間。
PerformanceEntry 實(shí)例會(huì)是下列接口實(shí)例之一:
PerformanceMark
PerformanceMeasure
PerformanceFrameTiming
PerformanceNavigationTiming
PerformanceResourceTiming
PerformancePaintTiming
例如在 Chrome DevTools 的控制臺(tái)打印 performance.getEntries(),
[Exposed=Window] interface PerformanceNavigationTiming : PerformanceResourceTiming { readonly attribute DOMHighResTimeStamp unloadEventStart; readonly attribute DOMHighResTimeStamp unloadEventEnd; readonly attribute DOMHighResTimeStamp domInteractive; readonly attribute DOMHighResTimeStamp domContentLoadedEventStart; readonly attribute DOMHighResTimeStamp domContentLoadedEventEnd; readonly attribute DOMHighResTimeStamp domComplete; readonly attribute DOMHighResTimeStamp loadEventStart; readonly attribute DOMHighResTimeStamp loadEventEnd; readonly attribute NavigationType type; readonly attribute unsigned short redirectCount; [Default] object toJSON(); };
{ connectEnd: 3.8349999995261896 connectStart: 3.8349999995261896 decodedBodySize: 74229 domComplete: 336.69000000008964 domContentLoadedEventEnd: 130.1899999998568 domContentLoadedEventStart: 129.47499999791034 domInteractive: 129.42000000111875 domainLookupEnd: 3.8349999995261896 domainLookupStart: 3.8349999995261896 duration: 339.76500000062515 encodedBodySize: 18430 entryType: "navigation" fetchStart: 3.8349999995261896 initiatorType: "navigation" loadEventEnd: 339.76500000062515 loadEventStart: 336.72999999907915 name: "https://developer.mozilla.org/en-US/docs/Web/API/Performance_API" nextHopProtocol: "h2" redirectCount: 0 redirectEnd: 0 redirectStart: 0 requestStart: 5.089999998745043 responseEnd: 15.745000000606524 responseStart: 5.395000000135042 secureConnectionStart: 0 serverTiming: [] startTime: 0 transferSize: 0 type: "back_forward" unloadEventEnd: 16.714999997930136 unloadEventStart: 16.709999999875436 workerStart: 0 }PerformanceResourceTiming
檢索和分析網(wǎng)絡(luò)加載應(yīng)用資源(例如 link/script/iframe標(biāo)簽、css中url()等)的詳細(xì)網(wǎng)絡(luò)計(jì)時(shí)數(shù)據(jù)。
[Exposed=(Window)] interface PerformanceResourceTiming : PerformanceEntry { readonly attribute DOMString initiatorType; readonly attribute DOMHighResTimeStamp redirectStart; readonly attribute DOMHighResTimeStamp redirectEnd; readonly attribute DOMHighResTimeStamp fetchStart; readonly attribute DOMHighResTimeStamp domainLookupStart; readonly attribute DOMHighResTimeStamp domainLookupEnd; readonly attribute DOMHighResTimeStamp connectStart; readonly attribute DOMHighResTimeStamp connectEnd; readonly attribute DOMHighResTimeStamp secureConnectionStart; readonly attribute DOMHighResTimeStamp requestStart; readonly attribute DOMHighResTimeStamp responseStart; readonly attribute DOMHighResTimeStamp responseEnd; serializer = {inherit, attribute}; };
{ connectEnd: 403.1199999990349 connectStart: 403.1199999990349 decodedBodySize: 33808 domainLookupEnd: 403.1199999990349 domainLookupStart: 403.1199999990349 duration: 1.6250000007858034 encodedBodySize: 33808 entryType: "resource" fetchStart: 403.1199999990349 initiatorType: "link" name: "https://developer.mozilla.org/static/fonts/locales/ZillaSlab-Regular.subset.bbc33fb47cf6.woff2" nextHopProtocol: "h2" redirectEnd: 0 redirectStart: 0 requestStart: 404.0950000016892 responseEnd: 404.7449999998207 responseStart: 404.3100000017148 secureConnectionStart: 0 serverTiming: [] startTime: 403.1199999990349 transferSize: 0 workerStart: 0 }PerformancePaintTiming
網(wǎng)頁(yè)構(gòu)建期間有關(guān)“繪制(paint)”(也稱為“渲染(render)”)操作的計(jì)時(shí)信息。 “繪制(paint)”是指將渲染樹(shù)轉(zhuǎn)換為屏幕上的像素。
interface PerformancePaintTiming : PerformanceEntry {};
{ duration: 0 entryType: "paint" name: "first-paint" startTime: 667.9050000020652 }
參考資料:
High Resolution Time Level 2
MDN - Performance API
Navigation Timing
Performance Timeline Level 2
文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。
轉(zhuǎn)載請(qǐng)注明本文地址:http://systransis.cn/yun/103884.html
摘要:從一次實(shí)驗(yàn)學(xué)習(xí)性能優(yōu)化之接口詳解下圖是接口的屬性提供給定頁(yè)面的與時(shí)間相關(guān)的性能信息包含了頁(yè)面瀏覽上下文的導(dǎo)航信息,比如大量獲取資源的重定向。返回當(dāng)前網(wǎng)頁(yè)事件的回調(diào)函數(shù)運(yùn)行結(jié)束時(shí)的毫秒時(shí)間戳。 從一次實(shí)驗(yàn)學(xué)習(xí)性能優(yōu)化 Web API之Performance 接口詳解 下圖是Performance 接口的屬性,提供給定頁(yè)面的與時(shí)間相關(guān)的性能信息.showImg(https://segmen...
摘要:回過(guò)頭來(lái)發(fā)現(xiàn),我們的項(xiàng)目,雖然在服務(wù)端層面做好了日志和性能統(tǒng)計(jì),但在前端對(duì)異常的監(jiān)控和性能的統(tǒng)計(jì)。對(duì)于前端的性能與異常上報(bào)的可行性探索是有必要的。這是我們頁(yè)面加載性能優(yōu)化需求中主要上報(bào)的相關(guān)信息。 概述 對(duì)于后臺(tái)開(kāi)發(fā)來(lái)說(shuō),記錄日志是一種非常常見(jiàn)的開(kāi)發(fā)習(xí)慣,通常我們會(huì)使用try...catch代碼塊來(lái)主動(dòng)捕獲錯(cuò)誤、對(duì)于每次接口調(diào)用,也會(huì)記錄下每次接口調(diào)用的時(shí)間消耗,以便我們監(jiān)控服務(wù)器接口...
摘要:性能時(shí)間線以一個(gè)統(tǒng)一的接口獲取由和所收集的性能數(shù)據(jù)。瀏覽器支持下表列舉了當(dāng)前主流瀏覽器對(duì)性能的支持,其中標(biāo)注星號(hào)的內(nèi)容并非來(lái)自于性能工作小組。 頁(yè)面的性能問(wèn)題一直是產(chǎn)品開(kāi)發(fā)過(guò)程中的重要一環(huán),很多公司也一直在使用各種方式監(jiān)控產(chǎn)品的頁(yè)面性能。從控制臺(tái)工具、Fiddler抓包工具,到使用DOMContentLoaded和document.onreadystatechange這種侵入式j(luò)ava...
摘要:當(dāng)一個(gè)按鈕沒(méi)有名字時(shí),屏幕閱讀器會(huì)宣布按鈕。雖然每個(gè)元素的目的對(duì)于有視覺(jué)的用戶來(lái)說(shuō)可能是顯而易見(jiàn)的,但對(duì)于依靠屏幕閱讀器的用戶來(lái)說(shuō)并非如此。屏幕閱讀器使視覺(jué)障礙的用戶能夠通過(guò)將文本內(nèi)容轉(zhuǎn)換為可以使用的表格如合成語(yǔ)音或盲文來(lái)使用您的網(wǎng)站。 Lighthouse是一個(gè)Google開(kāi)源的自動(dòng)化工具,主要用于改進(jìn)網(wǎng)絡(luò)應(yīng)用(移動(dòng)端)的質(zhì)量。目前測(cè)試項(xiàng)包括頁(yè)面性能、PWA、可訪問(wèn)性(無(wú)障礙)、最佳...
閱讀 1878·2021-11-11 16:54
閱讀 2091·2019-08-30 15:56
閱讀 2403·2019-08-30 15:44
閱讀 1364·2019-08-30 15:43
閱讀 1897·2019-08-30 11:07
閱讀 856·2019-08-29 17:11
閱讀 1504·2019-08-29 15:23
閱讀 3040·2019-08-29 13:01