diff options
Diffstat (limited to 'files/zh-cn/web/api/performance')
16 files changed, 1637 insertions, 0 deletions
diff --git a/files/zh-cn/web/api/performance/clearmarks/index.html b/files/zh-cn/web/api/performance/clearmarks/index.html new file mode 100644 index 0000000000..5ccd6a016b --- /dev/null +++ b/files/zh-cn/web/api/performance/clearmarks/index.html @@ -0,0 +1,132 @@ +--- +title: Performance.clearMarks() +slug: Web/API/Performance/clearMarks +translation_of: Web/API/Performance/clearMarks +--- +<div>{{APIRef("User Timing API")}}</div> + +<p><strong><code>clearMarks()</code></strong> 这个方法可以从浏览器的performance entry 缓存中移除声明的标记。如果调用这个方法时没有传递参数, 则所有带有{{domxref("PerformanceEntry.entryType","entry type")}}这类标记的{{domxref("PerformanceEntry","performance entries")}} 将从 performance entry 缓存区中被移除。</p> + +<h2 id="用法">用法</h2> + +<pre class="syntaxbox"><em>performance</em>.clearMarks(); +<em>performance</em>.clearMarks(name); +</pre> + +<h3 id="参数">参数</h3> + +<dl> + <dt>name {{optional_inline}}</dt> + <dd>{{domxref("DOMString")}} 表示时间戳的名字,如果没有提供这个参数, 则所有带有{{domxref("PerformanceEntry.entryType","entry type")}}这类标记的{{domxref("PerformanceEntry","performance entries")}} 将从 performance entry 缓存区中被移除。</dd> +</dl> + +<h3 id="返回值">返回值</h3> + +<dl> + <dt>void</dt> + <dd> </dd> +</dl> + +<h2 id="例子">例子</h2> + +<p>下面的例子演示<code>clearMarks() 的两种用法。</code></p> + +<pre class="brush: js">function clear_mark(name) { + if (performance.clearMarks === undefined) { + console.log("performance.clearMarks Not supported"); + return; + } + //移除所有标记了此名称的peformance entry + performance.clearMarks(name); +} +function clear_all_marks() { + if (performance.clearMarks === undefined) { + console.log("performance.clearMarks Not supported"); + return; + } + //从performance 缓冲区中移除所有标记的performance entry + performance.clearMarks(); +} +</pre> + +<h2 id="说明">说明</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">说明</th> + <th scope="col">状态</th> + <th scope="col">备注</th> + </tr> + <tr> + <td>{{SpecName('User Timing Level 2', '#dom-performance-clearmarks', 'clearMarks()')}}</td> + <td>{{Spec2('User Timing Level 2')}}</td> + <td>Clarifies <code>clearMarks()</code>.</td> + </tr> + <tr> + <td>{{SpecName('User Timing', '#dom-performance-clearmarks', 'clearMarks()')}}</td> + <td>{{Spec2('User Timing')}}</td> + <td>Basic definition.</td> + </tr> + </tbody> +</table> + +<h2 id="浏览器兼容性">浏览器兼容性</h2> + +<div>{{CompatibilityTable}}</div> + +<div id="compat-desktop"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Chrome</th> + <th>Edge</th> + <th>Firefox (Gecko)</th> + <th>Internet Explorer</th> + <th>Opera</th> + <th>Safari (WebKit)</th> + </tr> + <tr> + <td>Basic support</td> + <td>{{CompatChrome(43.0)}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>41</td> + <td>10</td> + <td>33</td> + <td>{{CompatNo}}</td> + </tr> + </tbody> +</table> +</div> + +<div id="compat-mobile"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Android</th> + <th>Android Webview</th> + <th>Edge</th> + <th>Firefox Mobile (Gecko)</th> + <th>Firefox OS</th> + <th>IE Phone</th> + <th>Opera Mobile</th> + <th>Safari Mobile</th> + <th>Chrome for Android</th> + </tr> + <tr> + <td>Basic support</td> + <td>{{CompatNo}}</td> + <td>{{CompatChrome(46.0)}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>42</td> + <td>42</td> + <td>10</td> + <td>33</td> + <td>{{CompatNo}}</td> + <td>{{CompatChrome(46.0)}}</td> + </tr> + </tbody> +</table> +</div> diff --git a/files/zh-cn/web/api/performance/clearmeasures/index.html b/files/zh-cn/web/api/performance/clearmeasures/index.html new file mode 100644 index 0000000000..66cd9b0685 --- /dev/null +++ b/files/zh-cn/web/api/performance/clearmeasures/index.html @@ -0,0 +1,134 @@ +--- +title: Performance.clearMeasures() +slug: Web/API/Performance/clearMeasures +translation_of: Web/API/Performance/clearMeasures +--- +<div>{{APIRef("User Timing API")}}</div> + +<p><strong><code>clearMeasures()</code></strong> 方法可以从浏览器的性能入口缓存区中移除声明的度量衡。如果这个方法被调用时没有传入参数,则所有 {{domxref("PerformanceEntry.entryType","entry type")}} 标记值为"<code>measure</code>" 的{{domxref("PerformanceEntry","性能实体")}}将被从性能入口缓存区中移除。</p> + +<p>{{AvailableInWorkers}}</p> + +<h2 id="用法">用法</h2> + +<pre class="syntaxbox"><em>performance</em>.clearMeasures(); +<em>performance</em>.clearMeasures(name); +</pre> + +<h3 id="参数">参数</h3> + +<dl> + <dt>name {{optional_inline}}</dt> + <dd>用于表述时间戳名称的 {{domxref("DOMString")}}。如果没有提供这个参数,则所有 {{domxref("PerformanceEntry.entryType","entry type")}} 标记值为"<code>measure</code>" 的{{domxref("PerformanceEntry","性能实体")}}将被移除。</dd> +</dl> + +<h3 id="返回值">返回值</h3> + +<dl> + <dt>void</dt> + <dd> </dd> +</dl> + +<h2 id="例子">例子</h2> + +<p>下面的两个例子演示了 <code>clearMeasures()</code> 的用法。</p> + +<pre class="brush: js">function clear_measure(name) { + if (performance.clearMeasures === undefined) { + console.log("performance.clearMeasures Not supported"); + return; + } + // 根据给定的 name <code>移除所有标记类型为 "measure" 的性能入口</code> + performance.clearMeasures(name); +} +function clear_all_measures() { + if (performance.clearMeasures === undefined) { + console.log("performance.clearMeasures Not supported"); + return; + } + // <code>移除性能缓存区中所有标记类型为 "measure" 的性能入口</code> + performance.clearMeasures(); +} +</pre> + +<h2 id="规范">规范</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Specification</th> + <th scope="col">Status</th> + <th scope="col">Comment</th> + </tr> + <tr> + <td>{{SpecName('User Timing Level 2', '#dom-performance-clearmeasures', 'clearMeasures()')}}</td> + <td>{{Spec2('User Timing Level 2')}}</td> + <td>Clarifies <code>clearMeasures()</code>.</td> + </tr> + <tr> + <td>{{SpecName('User Timing', '#dom-performance-clearmeasures', 'clearMeasures()')}}</td> + <td>{{Spec2('User Timing')}}</td> + <td>Basic definition.</td> + </tr> + </tbody> +</table> + +<h2 id="浏览器兼容性">浏览器兼容性</h2> + +<div>{{CompatibilityTable}}</div> + +<div id="compat-desktop"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Chrome</th> + <th>Edge</th> + <th>Firefox (Gecko)</th> + <th>Internet Explorer</th> + <th>Opera</th> + <th>Safari (WebKit)</th> + </tr> + <tr> + <td>Basic support</td> + <td>{{CompatChrome(43.0)}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>41</td> + <td>10</td> + <td>33</td> + <td>{{CompatNo}}</td> + </tr> + </tbody> +</table> +</div> + +<div id="compat-mobile"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Android</th> + <th>Android Webview</th> + <th>Edge</th> + <th>Firefox Mobile (Gecko)</th> + <th>Firefox OS</th> + <th>IE Phone</th> + <th>Opera Mobile</th> + <th>Safari Mobile</th> + <th>Chrome for Android</th> + </tr> + <tr> + <td>Basic support</td> + <td>{{CompatNo}}</td> + <td>{{CompatChrome(46.0)}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>42</td> + <td>42</td> + <td>10</td> + <td>33</td> + <td>{{CompatNo}}</td> + <td>{{CompatChrome(46.0)}}</td> + </tr> + </tbody> +</table> +</div> diff --git a/files/zh-cn/web/api/performance/clearresourcetimings/index.html b/files/zh-cn/web/api/performance/clearresourcetimings/index.html new file mode 100644 index 0000000000..e67b1cba7b --- /dev/null +++ b/files/zh-cn/web/api/performance/clearresourcetimings/index.html @@ -0,0 +1,85 @@ +--- +title: Performance.clearResourceTimings() +slug: Web/API/Performance/clearResourceTimings +translation_of: Web/API/Performance/clearResourceTimings +--- +<div>{{APIRef("Resource Timing API")}}</div> + +<p>The <strong><code>clearResourceTimings()</code></strong> method removes all {{domxref("PerformanceEntry","performance entries")}} with an {{domxref("PerformanceEntry.entryType","entryType")}} of "<code>resource</code>" from the browser's performance data buffer and sets the size of the performance data buffer to zero. To set the size of the browser's performance data buffer, use the {{domxref("Performance.setResourceTimingBufferSize()")}} method.</p> + +<p>{{AvailableInWorkers}}</p> + +<h2 id="Syntax">Syntax</h2> + +<pre class="syntaxbox"><em>performance</em>.clearResourceTimings(); +</pre> + +<h3 id="Arguments">Arguments</h3> + +<dl> + <dt>void</dt> + <dd> </dd> +</dl> + +<h3 id="Return_Value" name="Return_Value">Return value</h3> + +<dl> + <dt>none</dt> + <dd>This method has no return value.</dd> +</dl> + +<h2 id="Example">Example</h2> + +<pre class="brush: js">function load_resource() { + var image = new Image(); + image.src = "https://developer.mozilla.org/static/img/opengraph-logo.png"; +} +function clear_performance_timings() { + if (performance === undefined) { + log("Browser does not support Web Performance"); + return; + } + // Create a resource timing performance entry by loading an image + load_resource(); + + var supported = typeof performance.clearResourceTimings == "function"; + if (supported) { + console.log("Run: performance.clearResourceTimings()"); + performance.clearResourceTimings(); + } else { + console.log("performance.clearResourceTimings() NOT supported"); + return; + } + // getEntries should now return zero + var p = performance.getEntriesByType("resource"); + if (p.length == 0) + console.log("... Performance data buffer cleared"); + else + console.log("... Performance data buffer NOT cleared!"); +} +</pre> + +<h2 id="Specifications">Specifications</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Specification</th> + <th scope="col">Status</th> + <th scope="col">Comment</th> + </tr> + <tr> + <td>{{SpecName('Resource Timing', '#dom-performance-clearresourcetimings', 'clearResourceTimings()')}}</td> + <td>{{Spec2('Resource Timing')}}</td> + <td>Initial definition.</td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility">Browser compatibility</h2> + +<div> + + +<p>{{Compat("api.Performance.clearResourceTimings")}}</p> +</div> diff --git a/files/zh-cn/web/api/performance/getentries/index.html b/files/zh-cn/web/api/performance/getentries/index.html new file mode 100644 index 0000000000..f9033d7d7a --- /dev/null +++ b/files/zh-cn/web/api/performance/getentries/index.html @@ -0,0 +1,142 @@ +--- +title: Performance.getEntries() +slug: Web/API/Performance/getEntries +translation_of: Web/API/Performance/getEntries +--- +<div>{{APIRef("Performance Timeline API")}}</div> + +<p><strong><code>getEntries()</code></strong> 对于给定的filter,此方法返回 {{domxref("PerformanceEntry")}} 对象数组. 数组成员(入口)可以在显式的时间点用 performance <em>marks或</em><em>measures</em> 来创建(例如调用{{domxref("Performance.mark","mark()")}} 方法) .</p> + +<p class="note">此方法暴露给{{domxref("Window")}} 和 {{domxref("Worker")}}接口.</p> + +<h2 id="语法">语法</h2> + +<p>取全部:</p> + +<pre class="syntaxbox"><em>entries</em> = window.performance.getEntries(); +<em>entries</em> = window.performance.getEntries(<em>PerformanceEntryFilterOptions</em>); +</pre> + +<p>取特定:</p> + +<pre class="syntaxbox">entries = performance.getEntries({name: "entry_name", entryType: "mark"}); +</pre> + +<h3 id="参数">参数</h3> + +<dl> + <dt>PerformanceEntryFilterOptions {{optional_inline}}</dt> +</dl> + +<dl> + <dd><code>PerformanceEntryFilterOptions</code> 是一个带有以下键值的字典: + + <ul> + <li><code>"name"</code>, performance entry. 的名字</li> + <li><code>"entryType"</code>, entry 类型. 合法的entry类型可以从{{domxref("PerformanceEntry.entryType")}} 方法获取.</li> + <li><code>"initiatorType"</code>, 初始化资源的类型(例如一个HTML element). 其取值被 {{domxref("PerformanceResourceTiming.initiatorType")}} 接口所定义.</li> + </ul> + </dd> +</dl> + +<h3 id="Return_Value" name="Return_Value">返回值</h3> + +<dl> + <dt>entries</dt> + <dd>一个由符合filter条件的{{domxref("PerformanceEntry")}} 对象构成的数组 . 数组成员按PerformanceEntry.{{domxref("PerformanceEntry.startTime","startTime")}}时间顺序排列 . 如果没有符合filter条件的对象,那么返回空数组. 如果不带任何参数,返回全部entries.</dd> +</dl> + +<h2 id="Example">Example</h2> + +<pre class="brush: js">function use_PerformanceEntry_methods() { + log("PerformanceEntry tests ..."); + + if (performance.mark === undefined) { + log("... performance.mark Not supported"); + return; + } + + // Create some performance entries via the mark() method + performance.mark("Begin"); + do_work(50000); + performance.mark("End"); + performance.mark("Begin"); + do_work(100000); + performance.mark("End"); + do_work(200000); + performance.mark("End"); + + // Use getEntries() to iterate through the each entry + var p = performance.getEntries(); + for (var i=0; i < p.length; i++) { + log("Entry[" + i + "]"); + check_PerformanceEntry(p[i]); + } + + // Use getEntries(name, entryType) to get specific entries + p = performance.getEntries({name : "Begin", entryType: "mark"}); + for (var i=0; i < p.length; i++) { + log("Begin[" + i + "]"); + check_PerformanceEntry(p[i]); + } + + // Use getEntriesByType() to get all "mark" entries + p = performance.getEntriesByType("mark"); + for (var i=0; i < p.length; i++) { + log ("Mark only entry[" + i + "]: name = " + p[i].name + + "; startTime = " + p[i].startTime + + "; duration = " + p[i].duration); + } + + // Use getEntriesByName() to get all "mark" entries named "Begin" + p = performance.getEntriesByName("Begin", "mark"); + for (var i=0; i < p.length; i++) { + log ("Mark and Begin entry[" + i + "]: name = " + p[i].name + + "; startTime = " + p[i].startTime + + "; duration = " + p[i].duration); + } +} + +//entryType,name,initiatorType Examples +var p = performance.getEntries(); + +var ptyps = p.map((ele) => {return(ele.entryType)}); +//Array(94) [ "navigation", "resource", "resource", "resource", "resource", "resource", "resource", "resource", "resource", "resource", … ] + +var pnms = p.map((ele) => {return(ele.name)}); +//Array(94) [ "document", "https://csdnimg.cn/public/static/css/avatar.css", "https://csdnimg.cn/public/common/libs/jquery/jquery-1.9.1.min.js", "https://csdnimg.cn/rabbit/exposure-click/main-1.0.5.js", "https://csdnimg.cn/release/phoenix/production/main-e96db8abdf.js", "https://csdnimg.cn/pubfooter/js/tracking-1.0.2.js", "https://csdnimg.cn/public/common/toolbar/js/content_toolbar.js", "https://csdnimg.cn/release/phoenix/production/markdown_views-ea0013b516.css", "https://csdnimg.cn/search/baidu_search-1.1.2.js?v=201802071056&autorun=true&install=true&keyword=%E5%B0%8F%E7%A8%8B%E5%BA%8F%E6%89%A7%E8%A1%8C%E9%A1%BA%E5%BA%8F", "https://csdnimg.cn/release/phoenix/production/main-f869aa95a4.css", … ] + +var pityps = p.map((ele) => {return(ele.initiatorType)}); +//Array(94) [ "navigation", "link", "script", "script", "script", "script", "script", "link", "script", "link", … ] + +Specifications</pre> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Specification</th> + <th scope="col">Status</th> + <th scope="col">Comment</th> + </tr> + <tr> + <td>{{SpecName('Performance Timeline Level 2', '#dom-performance-getentries', 'getEntries()')}}</td> + <td>{{Spec2('Performance Timeline Level 2')}}</td> + <td><code>getEntries()</code> method has an optional argument.</td> + </tr> + <tr> + <td>{{SpecName('Performance Timeline', '#dom-performance-getentries', 'getEntries()')}}</td> + <td>{{Spec2('Performance Timeline')}}</td> + <td>Initial definition.</td> + </tr> + </tbody> +</table> + +<h2 id="浏览器兼容性">浏览器兼容性</h2> + +<div> +<div> + + +<p>{{Compat("api.Performance.getEntries")}}</p> +</div> +</div> diff --git a/files/zh-cn/web/api/performance/getentriesbyname/index.html b/files/zh-cn/web/api/performance/getentriesbyname/index.html new file mode 100644 index 0000000000..aa47b35ba1 --- /dev/null +++ b/files/zh-cn/web/api/performance/getentriesbyname/index.html @@ -0,0 +1,115 @@ +--- +title: performance.getEntriesByName() +slug: Web/API/Performance/getEntriesByName +tags: + - web性能 +translation_of: Web/API/Performance/getEntriesByName +--- +<div><strong><code>getEntriesByName()</code></strong>方法返回一个给定名称和name和type属性的{{domxref("PerformanceEntry")}}对象数组。在创建performance标记或在明确的时间点测量(比如手动调用{{domxref("Performance.mark","mark()")}}方法)也可以创建这样的对象数组。</div> + +<div></div> + +<p>在Workers中可以使用该方法。</p> + +<h2 id="语法">语法</h2> + +<pre class="syntaxbox"><em>entries</em> = window.performance.getEntriesByName(name, type); +</pre> + +<h3 id="参数">参数</h3> + +<dl> + <dt>name</dt> + <dd>The name of the entry to retrieve.</dd> + <dt>type {{optional_inline}}</dt> + <dd>The type of entry to retrieve such as "<code>mark</code>". The valid entry types are listed in {{domxref("PerformanceEntry.entryType")}}.</dd> +</dl> + +<h3 id="Return_Value" name="Return_Value">Return value</h3> + +<dl> + <dt>entries</dt> + <dd>A list of {{domxref("PerformanceEntry")}} objects that have the specified <code>name</code> and <code>type</code>. If the <code>type</code> argument is not specified, only the <code>name</code> will be used to determine the entries to return. The items will be in chronological order based on the entries' {{domxref("PerformanceEntry.startTime","startTime")}}. If no objects meet the specified criteria, an empty list is returned.</dd> +</dl> + +<h2 id="Example">Example</h2> + +<pre class="brush: js">function use_PerformanceEntry_methods() { + log("PerformanceEntry tests ..."); + + if (performance.mark === undefined) { + log("... performance.mark Not supported"); + return; + } + + // Create some performance entries via the mark() method + performance.mark("Begin"); + do_work(50000); + performance.mark("End"); + performance.mark("Begin"); + do_work(100000); + performance.mark("End"); + do_work(200000); + performance.mark("End"); + + // Use getEntries() to iterate through the each entry + var p = performance.getEntries(); + for (var i=0; i < p.length; i++) { + log("Entry[" + i + "]"); + check_PerformanceEntry(p[i]); + } + + // Use getEntries(name, entryType) to get specific entries + p = performance.getEntries({name : "Begin", entryType: "mark"}); + for (var i=0; i < p.length; i++) { + log("Begin[" + i + "]"); + check_PerformanceEntry(p[i]); + } + + // Use getEntriesByType() to get all "mark" entries + p = performance.getEntriesByType("mark"); + for (var i=0; i < p.length; i++) { + log ("Mark only entry[" + i + "]: name = " + p[i].name + + "; startTime = " + p[i].startTime + + "; duration = " + p[i].duration); + } + + // Use getEntriesByName() to get all "mark" entries named "Begin" + p = performance.getEntriesByName("Begin", "mark"); + for (var i=0; i < p.length; i++) { + log ("Mark and Begin entry[" + i + "]: name = " + p[i].name + + "; startTime = " + p[i].startTime + + "; duration = " + p[i].duration); + } +} +</pre> + +<h2 id="Specifications">Specifications</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Specification</th> + <th scope="col">Status</th> + <th scope="col">Comment</th> + </tr> + <tr> + <td>{{SpecName('Performance Timeline Level 2', '#dom-performance-getentriesbyname', 'getEntriesByName()')}}</td> + <td>{{Spec2('Performance Timeline Level 2')}}</td> + <td></td> + </tr> + <tr> + <td>{{SpecName('Performance Timeline', '#dom-performance-getentriesbyname', 'getEntriesByName()')}}</td> + <td>{{Spec2('Performance Timeline')}}</td> + <td>Initial definition.</td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility">Browser compatibility</h2> + +<div> + + +<p>{{Compat("api.Performance.getEntriesByName")}}</p> +</div> diff --git a/files/zh-cn/web/api/performance/getentriesbytype/index.html b/files/zh-cn/web/api/performance/getentriesbytype/index.html new file mode 100644 index 0000000000..e4ddbb1c09 --- /dev/null +++ b/files/zh-cn/web/api/performance/getentriesbytype/index.html @@ -0,0 +1,115 @@ +--- +title: performance.getEntriesByType() +slug: Web/API/Performance/getEntriesByType +tags: + - ZH +translation_of: Web/API/Performance/getEntriesByType +--- +<div>{{APIRef("Performance Timeline API")}}</div> + +<div><strong><code>getEntriesByType()</code></strong> 方法返回给定类型的 {{domxref("PerformanceEntry")}} 列表</div> + +<p>The list's members (<em>entries</em>) can be created by making performance <em>marks</em> or <em>measures</em> (for example by calling the {{domxref("Performance.mark","mark()")}} method) at explicit points in time.</p> + +<p>{{AvailableInWorkers}}</p> + +<h2 id="Syntax">Syntax</h2> + +<pre class="syntaxbox"><em>entries</em> = window.performance.getEntriesByType(type); +</pre> + +<h3 id="Arguments">Arguments</h3> + +<dl> + <dt>type</dt> + <dd>The type of entry to retrieve such as "<code>mark</code>". The valid entry types are listed in {{domxref("PerformanceEntry.entryType")}}.</dd> +</dl> + +<h3 id="Return_Value" name="Return_Value">Return value</h3> + +<dl> + <dt>entries</dt> + <dd>A list of {{domxref("PerformanceEntry")}} objects that have the specified <code>type</code>. The items will be in chronological order based on the entries' {{domxref("PerformanceEntry.startTime","startTime")}}. If no objects have the specified <code>type</code>, or no argument is provided, an empty list is returned.</dd> +</dl> + +<h2 id="Example">Example</h2> + +<pre class="brush: js">function usePerformanceEntryMethods() { + log("PerformanceEntry tests ..."); + + if (performance.mark === undefined) { + log("... performance.mark Not supported"); + return; + } + + // Create some performance entries via the mark() method + performance.mark("Begin"); + doWork(50000); + performance.mark("End"); + performance.mark("Begin"); + doWork(100000); + performance.mark("End"); + doWork(200000); + performance.mark("End"); + + // Use getEntries() to iterate through the each entry + var p = performance.getEntries(); + for (var i=0; i < p.length; i++) { + log("Entry[" + i + "]"); + checkPerformanceEntry(p[i]); + } + + // Use getEntries(name, entryType) to get specific entries + p = performance.getEntries({name : "Begin", entryType: "mark"}); + for (var i=0; i < p.length; i++) { + log("Begin[" + i + "]"); + checkPerformanceEntry(p[i]); + } + + // Use getEntriesByType() to get all "mark" entries + p = performance.getEntriesByType("mark"); + for (var i=0; i < p.length; i++) { + log ("Mark only entry[" + i + "]: name = " + p[i].name + + "; startTime = " + p[i].startTime + + "; duration = " + p[i].duration); + } + + // Use getEntriesByName() to get all "mark" entries named "Begin" + p = performance.getEntriesByName("Begin", "mark"); + for (var i=0; i < p.length; i++) { + log ("Mark and Begin entry[" + i + "]: name = " + p[i].name + + "; startTime = " + p[i].startTime + + "; duration = " + p[i].duration); + } +} +</pre> + +<h2 id="Specifications">Specifications</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Specification</th> + <th scope="col">Status</th> + <th scope="col">Comment</th> + </tr> + <tr> + <td>{{SpecName('Performance Timeline Level 2', '#dom-performance-getentriesbytype', 'getEntriesByType()')}}</td> + <td>{{Spec2('Performance Timeline Level 2')}}</td> + <td></td> + </tr> + <tr> + <td>{{SpecName('Performance Timeline', '#dom-performance-getentriesbytype', 'getEntriesByType()')}}</td> + <td>{{Spec2('Performance Timeline')}}</td> + <td>Initial definition.</td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility">Browser compatibility</h2> + +<div> + + +<p>{{Compat("api.Performance.getEntriesByType")}}</p> +</div> diff --git a/files/zh-cn/web/api/performance/index.html b/files/zh-cn/web/api/performance/index.html new file mode 100644 index 0000000000..a88936f95b --- /dev/null +++ b/files/zh-cn/web/api/performance/index.html @@ -0,0 +1,133 @@ +--- +title: Performance +slug: Web/API/Performance +tags: + - API + - Interface + - Performance + - Web Performance +translation_of: Web/API/Performance +--- +<div>{{APIRef("High Resolution Time")}}</div> + +<p><strong><code>Performance</code></strong> 接口可以获取到当前页面中与性能相关的信息。它是 High Resolution Time API 的一部分,同时也融合了 Performance Timeline API、<a href="https://developer.mozilla.org/en-US/docs/Web/API/Navigation_timing_API">Navigation Timing API</a>、 <a href="https://developer.mozilla.org/en-US/docs/Web/API/User_Timing_API">User Timing API</a> 和 <a href="https://developer.mozilla.org/en-US/docs/Web/API/Resource_Timing_API">Resource Timing API</a>。</p> + +<p>该类型的对象可以通过调用只读属性 {{domxref("Window.performance")}} 来获得。</p> + +<div class="note"> +<p><strong>注意:</strong>除了以下指出的情况外,该接口及其成员在 {{domxref("Web Worker")}} 中可用。此外,还需注意,performance 的创建和衡量都是同一环境下的。即,如果你在主线程(或者其他 worker)中创建了一个 performance,那么它在另外的 worker 线程中是不可用的;反之亦然。</p> +</div> + +<h2 id="属性">属性</h2> + +<p><em><code>Performance</code> 接口没有继承任何属性。</em></p> + +<dl> + <dt>{{deprecated_inline}}{{domxref("Performance.navigation")}} {{readonlyInline}}</dt> + <dd>{{domxref("PerformanceNavigation")}} 对象提供了在指定的时间段里发生的操作相关信息,包括页面是加载还是刷新、发生了多少次重定向等等。Not available in workers.</dd> + <dt>{{deprecated_inline}}{{domxref("Performance.timing")}} {{readonlyInline}}</dt> + <dd>{{domxref("PerformanceTiming")}} 对象包含延迟相关的性能信息。Not available in workers.</dd> + <dt>{{domxref("Performance.memory", "performance.memory")}} {{Non-standard_inline}}</dt> + <dd>其是 Chrome 添加的一个非标准扩展,这个属性提供了一个可以获取到基本内存使用情况的对象。<strong>不应该</strong>使用这个非标准的 API。</dd> + <dt>{{domxref("Performance.timeOrigin")}} {{readonlyInline}} {{Non-standard_inline}}</dt> + <dd>返回性能测量开始时的时间的高精度时间戳。</dd> + <dt> + <h3 id="事件处理程序">事件处理程序</h3> + </dt> + <dt>{{domxref("Performance.onresourcetimingbufferfull")}}</dt> + <dd>一个回调的 {{domxref("EventTarget")}},当触发 {{event("resourcetimingbufferfull")}} 事件的时候会被调用。</dd> +</dl> + +<h2 id="方法">方法</h2> + +<p><em><em><code>Performance</code> 接口没有继承任何方法。</em></em></p> + +<dl> + <dt>{{domxref("Performance.clearMarks()")}}</dt> + <dd>将给定的 mark 从浏览器的性能输入缓冲区中移除。</dd> + <dt>{{domxref("Performance.clearMeasures()")}}</dt> + <dd>将给定的 measure 从浏览器的性能输入缓冲区中移除。</dd> + <dt>{{domxref("Performance.clearResourceTimings()")}}</dt> + <dd>从浏览器的性能数据缓冲区中移除所有 {{domxref("PerformanceEntry.entryType","entryType")}} 是 "<code>resource</code>" 的 {{domxref("PerformanceEntry","performance entries")}}。</dd> + <dt>{{domxref("Performance.getEntries()")}}</dt> + <dd>基于给定的 <em>filter </em>返回一个 {{domxref("PerformanceEntry")}} 对象的列表。</dd> + <dt>{{domxref("Performance.getEntriesByName()")}}</dt> + <dd>基于给定的 <em>name </em>和 <em>entry type </em>返回一个 {{domxref("PerformanceEntry")}} 对象的列表。</dd> + <dt>{{domxref("Performance.getEntriesByType()")}}</dt> + <dd>基于给定的 <em>entry type </em>返回一个 {{domxref("PerformanceEntry")}} 对象的列表</dd> + <dt>{{domxref("Performance.mark()")}}</dt> + <dd>根据给出 name 值,在浏览器的性能输入缓冲区中创建一个相关的{{domxref("DOMHighResTimeStamp","timestamp")}}</dd> + <dt>{{domxref("Performance.measure()")}}</dt> + <dd>在浏览器的指定 <em>start mark 和 end mark</em> 间的性能输入缓冲区中创建一个指定的 {{domxref("DOMHighResTimeStamp","timestamp")}}</dd> + <dt>{{domxref("Performance.now()")}}</dt> + <dd>返回一个表示从性能测量时刻开始经过的毫秒数 {{domxref("DOMHighResTimeStamp")}}</dd> + <dt>{{domxref("Performance.setResourceTimingBufferSize()")}}</dt> + <dd>将浏览器的资源 timing 缓冲区的大小设置为 "<code>resource</code>" {{domxref("PerformanceEntry.entryType","type")}} {{domxref("PerformanceEntry","performance entry")}} 对象的指定数量</dd> + <dt>{{domxref("Performance.toJSON()")}}</dt> + <dd>其是一个 JSON 格式转化器,返回 <code>Performance</code> 对象的 JSON 对象</dd> +</dl> + +<h2 id="规范">规范</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Specification</th> + <th scope="col">Status</th> + <th scope="col">Comment</th> + </tr> + <tr> + <td>{{SpecName('Highres Time Level 3', '#dom-performance-timeorigin','timeOrigin')}}</td> + <td>{{Spec2('Highres Time Level 3')}}</td> + <td>Defines <code>timeOrigin</code> property.</td> + </tr> + <tr> + <td>{{SpecName('Highres Time Level 2', '#the-performance-interface', 'toJSON()')}}</td> + <td>{{Spec2('Highres Time Level 2')}}</td> + <td>Defines <code>toJson()</code> method.</td> + </tr> + <tr> + <td>{{SpecName('Highres Time', '#the-performance-interface', 'Performance')}}</td> + <td>{{Spec2('Highres Time')}}</td> + <td>Defines <code>now()</code> method.</td> + </tr> + <tr> + <td>{{SpecName('Navigation Timing', '#sec-window.performance-attribute', 'Performance')}}</td> + <td>{{Spec2('Navigation Timing')}}</td> + <td>Defines <code>timing</code> and <code>navigation</code> properties.</td> + </tr> + <tr> + <td>{{SpecName('Performance Timeline Level 2', '#extensions-to-the-performance-interface', 'Performance extensions')}}</td> + <td>{{Spec2('Performance Timeline Level 2')}}</td> + <td>Changes <code>getEntries()</code> interface.</td> + </tr> + <tr> + <td>{{SpecName('Performance Timeline', '#sec-window.performance-attribute', 'Performance extensions')}}</td> + <td>{{Spec2('Performance Timeline')}}</td> + <td>Defines <code>getEntries()</code>, <code>getEntriesByType()</code> and <code>getEntriesByName()</code> methods.</td> + </tr> + <tr> + <td>{{SpecName('Resource Timing', '#extensions-performance-interface', 'Performance extensions')}}</td> + <td>{{Spec2('Resource Timing')}}</td> + <td>Defines <code>clearResourceTimings()</code> and <code>setResourceTimingBufferSize()</code> methods and the <code>onresourcetimingbufferfull</code> property.</td> + </tr> + <tr> + <td>{{SpecName('User Timing Level 2', '#extensions-performance-interface', 'Performance extensions')}}</td> + <td>{{Spec2('User Timing Level 2')}}</td> + <td>Clarifies <code>mark()</code>, <code>clearMark()</code>, <code>measure()</code> and <code>clearMeasure()</code> methods.</td> + </tr> + <tr> + <td>{{SpecName('User Timing', '#extensions-performance-interface', 'Performance extensions')}}</td> + <td>{{Spec2('User Timing')}}</td> + <td>Defines <code>mark()</code>, <code>clearMark()</code>, <code>measure()</code> and <code>clearMeasure()</code> methods.</td> + </tr> + </tbody> +</table> + +<h2 id="浏览器兼容性">浏览器兼容性</h2> + +<div class="hidden"> +<p>The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out <a href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> and send us a pull request.</p> +</div> + +<p>{{Compat("api.Performance")}}</p> diff --git a/files/zh-cn/web/api/performance/mark/index.html b/files/zh-cn/web/api/performance/mark/index.html new file mode 100644 index 0000000000..2ad91c1edb --- /dev/null +++ b/files/zh-cn/web/api/performance/mark/index.html @@ -0,0 +1,154 @@ +--- +title: Performance.mark() +slug: Web/API/Performance/mark +tags: + - 性能 + - 性能追踪 +translation_of: Web/API/Performance/mark +--- +<p>{{APIRef("User Timing API")}}</p> + +<p><strong><code>mark()</code></strong> 方法在浏览器的性能缓冲区中使用给定名称添加一个{{domxref("DOMHighResTimeStamp","timestamp(时间戳)")}} <em>。</em></p> + +<p><em>应用</em>定义的时间戳可以通过 {{domxref("Performance")}} 接口的一个 <code>getEntries*()</code> 方法({{domxref("Performance.getEntries","getEntries()")}}, {{domxref("Performance.getEntriesByName","getEntriesByName()")}} 或者 {{domxref("Performance.getEntriesByType","getEntriesByType()")}})检索到。</p> + +<p><code>标记</code> 的 {{domxref("PerformanceEntry","performance entry")}}将具有以下属性值:</p> + +<ul> + <li>{{domxref("PerformanceEntry.entryType","entryType")}} - 设置为 "<code>mark</code>".</li> + <li>{{domxref("PerformanceEntry.name","name")}} - 设置为mark被创建时给出的 "<font face="consolas, Liberation Mono, courier, monospace"><span style="background-color: rgba(220, 220, 220, 0.5);">name</span></font>"。</li> + <li>{{domxref("PerformanceEntry.startTime","startTime")}} - 设置为 <code>mark()</code> 方法被调用时的 {{domxref("DOMHighResTimeStamp","timestamp")}} 。</li> + <li>{{domxref("PerformanceEntry.duration","duration")}} - 设置为 "<code>0</code>" (标记没有持续时间).</li> +</ul> + +<p>如果这个方法被指定的 <code>name</code> 已经存在于{{domxref("PerformanceTiming")}} 接口, 会抛出一个{{jsxref("SyntaxError")}}错误。</p> + +<h2 id="语法">语法</h2> + +<pre class="syntaxbox"><em>performance</em>.mark(name); +</pre> + +<h3 id="参数">参数</h3> + +<dl> + <dt>name</dt> + <dd>一个表示标记名称的{{domxref("DOMString")}}。</dd> +</dl> + +<h3 id="返回值">返回值</h3> + +<dl> + <dt> 无</dt> + <dd> </dd> +</dl> + +<h2 id="实例">实例</h2> + +<p>下面的示例演示如何使用 <code>mark()</code> 来创建和检索{{domxref("PerformanceMark")}}条目。</p> + +<p> </p> + +<pre class="brush: js">// 创建一些标记。 +performance.mark("squirrel"); +performance.mark("squirrel"); +performance.mark("monkey"); +performance.mark("monkey"); +performance.mark("dog"); +performance.mark("dog"); + +// 获取所有的 PerformanceMark 条目。 +const allEntries = performance.getEntriesByType("mark"); +console.log(allEntries.length); +// 6 + +// 获取所有的 "monkey" PerformanceMark 条目。 +const monkeyEntries = performance.getEntriesByName("monkey"); +console.log(monkeyEntries.length); +// 2 + +// 删除所有标记。 +performance.clearMarks();</pre> + +<p> </p> + +<h2 id="规范">规范</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">规范</th> + <th scope="col">状态</th> + <th scope="col">注释</th> + </tr> + <tr> + <td>{{SpecName('User Timing Level 2', '#dom-performance-mark', 'mark()')}}</td> + <td>{{Spec2('User Timing Level 2')}}</td> + <td>阐明 <code>mark()</code> 处理模型。</td> + </tr> + <tr> + <td>{{SpecName('User Timing', '#dom-performance-mark', 'mark()')}}</td> + <td>{{Spec2('User Timing')}}</td> + <td>基础定义。</td> + </tr> + </tbody> +</table> + +<h2 id="浏览器兼容">浏览器兼容</h2> + +<div>{{CompatibilityTable}}</div> + +<div id="compat-desktop"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Chrome</th> + <th>Edge</th> + <th>Firefox (Gecko)</th> + <th>Internet Explorer</th> + <th>Opera</th> + <th>Safari (WebKit)</th> + </tr> + <tr> + <td>Basic Support</td> + <td>{{CompatChrome(43.0)}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>41</td> + <td>10</td> + <td>33</td> + <td>{{CompatNo}}</td> + </tr> + </tbody> +</table> +</div> + +<div id="compat-mobile"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Android</th> + <th>Android Webview</th> + <th>Edge</th> + <th>Firefox Mobile (Gecko)</th> + <th>Firefox OS</th> + <th>IE Phone</th> + <th>Opera Mobile</th> + <th>Safari Mobile</th> + <th>Chrome for Android</th> + </tr> + <tr> + <td>Basic Support</td> + <td>{{CompatNo}}</td> + <td>{{CompatChrome(46.0)}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>42</td> + <td>42</td> + <td>10</td> + <td>33</td> + <td>{{CompatNo}}</td> + <td>{{CompatChrome(46.0)}}</td> + </tr> + </tbody> +</table> +</div> diff --git a/files/zh-cn/web/api/performance/measure/index.html b/files/zh-cn/web/api/performance/measure/index.html new file mode 100644 index 0000000000..a8b466a9a8 --- /dev/null +++ b/files/zh-cn/web/api/performance/measure/index.html @@ -0,0 +1,108 @@ +--- +title: Performance.measure() +slug: Web/API/Performance/measure +tags: + - Performance API + - 网页性能 +translation_of: Web/API/Performance/measure +--- +<div>{{APIRef("User Timing API")}}</div> + +<p> <strong><code>measure()</code></strong> 方法在浏览器性能记录缓存中创建了一个名为{{domxref("DOMHighResTimeStamp","时间戳")}}的记录来记录两个特殊标志位(通常称为开始标志和结束标志)。 被命名的{{domxref("DOMHighResTimeStamp","时间戳")}}称为一次测量(measure)。</p> + +<p>{{AvailableInWorkers}}</p> + +<p>The <code>measure</code> 可以被{{domxref("Performance")}} 接口 <code>getEntries*()</code> 中的方法检查到({{domxref("Performance.getEntries","getEntries()")}}, {{domxref("Performance.getEntriesByName","getEntriesByName()")}} 或者 {{domxref("Performance.getEntriesByType","getEntriesByType()")}}).</p> + +<p>The <code>measure's</code> {{domxref("PerformanceEntry","performance entry")}} will have the following property values:</p> + +<ul> + <li>{{domxref("PerformanceEntry.entryType","entryType")}} - set to "<code>measure</code>".</li> + <li>{{domxref("PerformanceEntry.name","name")}} - set to the "<code>name</code>" given when the measure was created.</li> + <li>{{domxref("PerformanceEntry.startTime","startTime")}} - set to the start mark {{domxref("DOMHighResTimeStamp","timestamp")}}.</li> + <li>{{domxref("PerformanceEntry.duration","duration")}} - set to a {{domxref("DOMHighResTimeStamp")}} that is the duration of the measure (typically, the end mark timestamp minus the start mark timestamp).</li> +</ul> + +<h2 id="语法">语法</h2> + +<pre class="syntaxbox"><em>performance</em>.measure(name, startMark, endMark); +</pre> + +<h3 id="参数">参数</h3> + +<dl> + <dt>name</dt> + <dd>一个 {{domxref("DOMString")}}, 代表测量的名字。</dd> + <dt>startMark {{optional_inline}}</dt> + <dd>一个 {{domxref("DOMString")}}, 代表测量的开始标志名字。 May also be the name of a {{domxref("PerformanceTiming")}} property.</dd> + <dt>endMark {{optional_inline}}</dt> + <dd>一个{{domxref("DOMString")}}, 代表测量的结束标志名字。May also be the name of a {{domxref("PerformanceTiming")}} property.</dd> +</dl> + +<h3 id="返回值">返回值</h3> + +<dl> + <dt>void</dt> + <dd> </dd> +</dl> + +<h2 id="例子">例子</h2> + +<p>以下例子展示如何在浏览器性能记录缓存中使用 <code>measure()</code>创建一个新的测量记录{{domxref("PerformanceEntry","performance entry")}} 。</p> + +<pre class="brush: js">// 以一个标志开始。 +performance.mark("mySetTimeout-start"); + +// 等待一些时间。 +setTimeout(function() { + // 标志时间的结束。 + performance.mark("mySetTimeout-end"); + + // 测量两个不同的标志。 + performance.measure( + "mySetTimeout", + "mySetTimeout-start", + "mySetTimeout-end" + ); + + // 获取所有的测量输出。 + // 在这个例子中只有一个。 + var measures = performance.getEntriesByName("mySetTimeout"); + var measure = measures[0]; + console.log("setTimeout milliseconds:", measure.duration) + + // 清除存储的标志位 + performance.clearMarks(); + performance.clearMeasures(); +}, 1000); +</pre> + +<h2 id="详细说明">详细说明</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">详细说明</th> + <th scope="col">状态</th> + <th scope="col">评论</th> + </tr> + <tr> + <td>{{SpecName('User Timing Level 2', '#dom-performance-measure', 'measure()')}}</td> + <td>{{Spec2('User Timing Level 2')}}</td> + <td>Clarifies <code>measure()</code> processing model.</td> + </tr> + <tr> + <td>{{SpecName('User Timing', '#dom-performance-measure', 'measure()')}}</td> + <td>{{Spec2('User Timing')}}</td> + <td>Basic definition.</td> + </tr> + </tbody> +</table> + +<h2 id="浏览器兼容性">浏览器兼容性</h2> + +<div> + + +<p>{{Compat("api.Performance.measure")}}</p> +</div> diff --git a/files/zh-cn/web/api/performance/navigation/index.html b/files/zh-cn/web/api/performance/navigation/index.html new file mode 100644 index 0000000000..c40354d771 --- /dev/null +++ b/files/zh-cn/web/api/performance/navigation/index.html @@ -0,0 +1,51 @@ +--- +title: Performance.navigation +slug: Web/API/Performance/navigation +tags: + - API + - Navigation Timing + - Performance +translation_of: Web/API/Performance/navigation +--- +<p>{{APIRef("Navigation Timing")}}</p> + +<h2 id="概要">概要</h2> + +<p>只读属性 <code><strong>Performance</strong></code><strong><code>.navigation </code></strong>会返回一个 {{domxref("PerformanceNavigation")}} 对象。这个对象表示出现在当前浏览上下文的 navigation 类型,比如获取某个资源所需要的重定向次数。</p> + +<h2 id="语法">语法</h2> + +<pre class="syntaxbox"><em>navObject</em> = <em>performance</em>.navigation;</pre> + +<h2 id="规范">规范</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Specification</th> + <th scope="col">Status</th> + <th scope="col">Comment</th> + </tr> + <tr> + <td>{{SpecName('Navigation Timing', '#sec-window.performance-attribute', 'Performance.navigation')}}</td> + <td>{{Spec2('Navigation Timing')}}</td> + <td>Initial definition.</td> + </tr> + </tbody> +</table> + +<h2 id="浏览器兼容性">浏览器兼容性</h2> + +<div> +<div> + + +<p>{{Compat("api.Performance.navigation")}}</p> +</div> +</div> + +<h2 id="相关链接">相关链接</h2> + +<ul> + <li>这个功能属于接口 {{domxref("Performance")}} .</li> +</ul> diff --git a/files/zh-cn/web/api/performance/now/index.html b/files/zh-cn/web/api/performance/now/index.html new file mode 100644 index 0000000000..61b07fab1d --- /dev/null +++ b/files/zh-cn/web/api/performance/now/index.html @@ -0,0 +1,107 @@ +--- +title: Performance.now() +slug: Web/API/Performance/now +tags: + - API + - Performance + - Web Performance API +translation_of: Web/API/Performance/now +--- +<p>{{APIRef("High Resolution Timing")}}</p> + +<p><code><strong>performance.now()</strong></code>方法返回一个精确到毫秒的 {{domxref("DOMHighResTimeStamp")}} 。</p> + +<div class="warning"> +<p>这个时间戳实际上并不是高精度的。为了降低像<a href="https://spectreattack.com/">Spectre</a>这样的安全威胁,各类浏览器对该类型的值做了不同程度上的四舍五入处理。(Firefox从Firefox 59开始四舍五入到2毫秒精度)一些浏览器还可能对这个值作稍微的随机化处理。这个值的精度在未来的版本中可能会再次改善;浏览器开发者还在调查这些时间测定攻击和如何更好的缓解这些攻击。</p> +</div> + +<p>{{AvailableInWorkers}}</p> + +<p>返回值表示为从<a href="/en-US/docs/Web/API/DOMHighResTimeStamp#The_time_origin">time origin</a>之后到当前调用时经过的时间</p> + +<p>牢记如下几点:</p> + +<ul> + <li>在以{{domxref("Window")}}上下文创建各个worker中,<code>performance.now()</code>的值要比在创建这些worker的window中的小。它原来等于main上下文的<code>t0</code>,但是现在不是了。</li> + <li>在共享worker或服务worker中,在worker中的值可能要比main上下文中高,因为window对象可能在这些worker之后创建。</li> +</ul> + +<h2 id="语法">语法</h2> + +<pre class="notranslate">const t = window.performance.now(); +</pre> + +<h2 id="示例">示例</h2> + +<pre class="brush: js notranslate">const t0 = window.performance.now(); +doSomething(); +const t1 = window.performance.now(); +console.log("doSomething函数执行了" + (t1 - t0) + "毫秒.") +</pre> + +<p>和JavaScript中其他可用的时间类函数(比如<code><a href="/zh-CN/docs/JavaScript/Reference/Global_Objects/Date/now" title="/zh-CN/docs/JavaScript/Reference/Global_Objects/Date/now">Date.now</a></code>)不同的是,<code>window.performance.now()</code>返回的时间戳没有被限制在一毫秒的精确度内,相反,它们以浮点数的形式表示时间,精度最高可达微秒级。</p> + +<p>另外一个不同点是,<code>window.performance.now()</code>是以一个恒定的速率慢慢增加的,它不会受到系统时间的影响(系统时钟可能会被手动调整或被NTP等软件篡改)。另外,<code>performance.timing.navigationStart + performance.now()</code> 约等于 <code>Date.now()</code>。</p> + +<h2 id="时间精度降低">时间精度降低</h2> + +<p>为了提供对定时攻击和指纹的保护,performance.now()的精度可能会根据浏览器的设置而被舍弃。<br> + 在Firefox中,privacy.reduceTimerPrecision偏好是默认启用的,默认值为1ms。</p> + +<pre class="notranslate">// 降低时间精度 (1ms) 在 Firefox 60 +performance.now(); +// 8781416 +// 8781815 +// 8782206 +// ... + + +// 降低时间经度 当 `privacy.resistFingerprinting` 启用 +performance.now(); +// 8865400 +// 8866200 +// 8866700 +// ...</pre> + +<p>在Firefox中,您还可以启用 <code>privacy.resistFingerprinting</code> 这将精度改为100ms或<code>privacy.resistFingerprinting.reduceTimerPrecision.microseconds</code> 的值,以较大者为准。</p> + +<p>从Firefox 79开始,如果您使用{{HTTPHeader("Cross-Origin-Opener-Policy")}}和{{HTTPHeader("Cross-Origin-Embedder-Policy")}}头来跨源隔离您的文档,就可以使用高分辨率定时器。</p> + +<pre class="notranslate">Cross-Origin-Opener-Policy: same-origin +Cross-Origin-Embedder-Policy: require-corp</pre> + +<p>这些头确保顶层文档不会与跨源文档共享浏览上下文组。COOP过程--隔离你的文档,潜在的攻击者如果在弹出窗口中打开你的全局对象,就无法访问它,从而防止一组被称为 <a href="https://github.com/xsleaks/xsleaks">XS-Leaks</a> 的跨源攻击。</p> + +<h2 id="规范">规范</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Specification</th> + <th scope="col">Status</th> + <th scope="col">Comment</th> + </tr> + <tr> + <td>{{SpecName('Highres Time Level 2', '#dom-performance-now', 'performance.now()')}}</td> + <td>{{Spec2('Highres Time Level 2')}}</td> + <td>Stricter definitions of interfaces and types.</td> + </tr> + <tr> + <td>{{SpecName('Highres Time', '#dom-performance-now', 'performance.now()')}}</td> + <td>{{Spec2('Highres Time')}}</td> + <td>Initial definition</td> + </tr> + </tbody> +</table> + +<h2 id="浏览器兼容性">浏览器兼容性</h2> + + + +<p>{{Compat("api.Performance.now")}}</p> + +<h2 id="相关链接">相关链接</h2> + +<ul> + <li><a href="http://updates.html5rocks.com/2012/08/When-milliseconds-are-not-enough-performance-now" title="http://updates.html5rocks.com/2012/08/When-milliseconds-are-not-enough-performance-now">When milliseconds are not enough: performance.now() </a>from HTML5 Rocks</li> +</ul> diff --git a/files/zh-cn/web/api/performance/onresourcetimingbufferfull/index.html b/files/zh-cn/web/api/performance/onresourcetimingbufferfull/index.html new file mode 100644 index 0000000000..e6bcbb1ec1 --- /dev/null +++ b/files/zh-cn/web/api/performance/onresourcetimingbufferfull/index.html @@ -0,0 +1,126 @@ +--- +title: Performance.onresourcetimingbufferfull +slug: Web/API/Performance/onresourcetimingbufferfull +translation_of: Web/API/Performance/onresourcetimingbufferfull +--- +<div>{{APIRef("Resource Timing API")}}</div> + +<p><strong><code>onresourcetimingbufferfull</code></strong> 属性是一个在{{event("resourcetimingbufferfull")}}事件触发时会被调用的 {{domxref("EventHandler","event handler")}} 。这个事件当浏览器的资源时间性能缓冲区已满时会触发。</p> + +<h2 id="Syntax" name="Syntax">语法</h2> + +<pre class="syntaxbox">callback = <em>performance</em>.onresourcetimingbufferfull = buffer_full_cb; +</pre> + +<h3 id="Return_Value" name="Return_Value">返回值</h3> + +<dl> + <dt>callback</dt> + <dd>一个当{{event("resourcetimingbufferfull")}} 事件触发时调用的{{domxref("EventHandler")}} 。</dd> +</dl> + +<h2 id="例子">例子</h2> + +<p>下面的示例在<code>onresourcetimingbufferfull属性上</code>设置一个回调函数。</p> + +<pre class="brush: js">function buffer_full(event) { + console.log("WARNING: Resource Timing Buffer is FULL!"); + performance.setResourceTimingBufferSize(200); +} +function init() { + // Set a callback if the resource buffer becomes filled + performance.onresourcetimingbufferfull = buffer_full; +} +<body onload="init()"> +</pre> + +<h2 id="规范">规范</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Specification</th> + <th scope="col">Status</th> + <th scope="col">Comment</th> + </tr> + <tr> + <td>{{SpecName('Resource Timing', '#dom-performance-onresourcetimingbufferfull', 'onresourcetimingbufferfull')}}</td> + <td>{{Spec2('Resource Timing')}}</td> + <td>Initial definition.</td> + </tr> + </tbody> +</table> + +<h2 id="浏览器兼容性">浏览器兼容性</h2> + +<div>{{CompatibilityTable}}</div> + +<div id="compat-desktop"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Chrome</th> + <th>Firefox (Gecko)</th> + <th>Internet Explorer</th> + <th>Opera</th> + <th>Safari (WebKit)</th> + </tr> + <tr> + <td>Basic support.</td> + <td>{{CompatVersionUnknown}} + <p>{{property_prefix("-webkit")}}<br> + {{CompatChrome(46)}} (unprefixed)<br> + {{CompatChrome(57)}} (prefixed version removed)</p> + </td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + </tr> + </tbody> +</table> +</div> + +<div id="compat-mobile"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Android Webview</th> + <th>Chrome for Android</th> + <th>Firefox Mobile (Gecko)</th> + <th>Firefox OS</th> + <th>IE Phone</th> + <th>Opera Mobile</th> + <th>Safari Mobile</th> + </tr> + <tr> + <td>Basic support.</td> + <td>{{CompatVersionUnknown}} + <p>{{property_prefix("-webkit")}}<br> + {{CompatChrome(46)}} (unprefixed)<br> + {{CompatChrome(57)}} (prefixed version removed)</p> + </td> + <td>{{CompatVersionUnknown}} + <p>{{property_prefix("-webkit")}}<br> + {{CompatChrome(46)}} (unprefixed)<br> + {{CompatChrome(57)}} (prefixed version removed)</p> + </td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatNo}}</td> + </tr> + </tbody> +</table> +</div> + +<h2 id="参见">参见</h2> + +<ul> + <li>{{event("resourcetimingbufferfull")}} event</li> + <li>{{domxref("Performance.clearResourceTimings","Performance.clearResourceTimings()")}}</li> + <li>{{domxref("Performance.setResourceTimingBufferSize","Performance.setResourceTimingBufferSize()")}}</li> +</ul> diff --git a/files/zh-cn/web/api/performance/timeorigin/index.html b/files/zh-cn/web/api/performance/timeorigin/index.html new file mode 100644 index 0000000000..d7d38f6781 --- /dev/null +++ b/files/zh-cn/web/api/performance/timeorigin/index.html @@ -0,0 +1,85 @@ +--- +title: Performance.timeOrigin +slug: Web/API/Performance/timeOrigin +translation_of: Web/API/Performance/timeOrigin +--- +<p>{{SeeCompatTable}}{{APIRef("High Resolution Time")}}</p> + +<p>接口 {{domxref("Performance")}} 的只读属性 <strong><code>timeOrigin</code></strong> 返回一个表示 the performance measurement 开始时间的高精度 timestamp</p> + +<h2 id="语法">语法</h2> + +<pre class="syntaxbox">var <em>timeOrigin</em> = performance.timeOrigin</pre> + +<h3 id="值">值</h3> + +<p>高精度 timestamp,例如 1518354643295.86</p> + +<h2 id="Specifications">Specifications</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Specification</th> + <th scope="col">Status</th> + <th scope="col">Comment</th> + </tr> + <tr> + <td>{{SpecName('Highres Time Level 3','#dom-performance-timeorigin','timeOrigin')}}</td> + <td>{{Spec2('Highres Time Level 3')}}</td> + <td>Initial definition.</td> + </tr> + </tbody> +</table> + +<h2 id="Browser_Compatibility">Browser Compatibility</h2> + +<div>{{CompatibilityTable}}</div> + +<div id="compat-desktop"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Chrome</th> + <th>Firefox (Gecko)</th> + <th>Internet Explorer</th> + <th>Opera</th> + <th>Safari (WebKit)</th> + </tr> + <tr> + <td>Basic support</td> + <td>{{CompatChrome(62)}}</td> + <td>{{CompatGeckoDesktop(59)}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatOpera(49)}}</td> + <td>{{CompatUnknown}}</td> + </tr> + </tbody> +</table> +</div> + +<div id="compat-mobile"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Android Webview</th> + <th>Chrome for Android</th> + <th>Firefox Mobile (Gecko)</th> + <th>IE Mobile</th> + <th>Opera Mobile</th> + <th>Safari Mobile</th> + </tr> + <tr> + <td>Basic support</td> + <td>{{CompatChrome(62)}}</td> + <td>{{CompatChrome(62)}}</td> + <td>{{CompatGeckoMobile(59)}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatOperaMobile(49)}}</td> + <td>{{CompatUnknown}}只读属性 <strong><code><font face="Courier New">timeOrigin</font></code></strong> timestampperformance.timeOrigin</td> + </tr> + </tbody> +</table> +</div> diff --git a/files/zh-cn/web/api/performance/timing/index.html b/files/zh-cn/web/api/performance/timing/index.html new file mode 100644 index 0000000000..f9e888d388 --- /dev/null +++ b/files/zh-cn/web/api/performance/timing/index.html @@ -0,0 +1,47 @@ +--- +title: Performance.timing +slug: Web/API/Performance/timing +tags: + - Navigation Timing + - Navigation Timing API + - Performance +translation_of: Web/API/Performance/timing +--- +<p>{{APIRef("Navigation Timing")}}{{deprecated_header}}</p> + +<div class="warning"> +<p>该属性在 <a href="https://w3c.github.io/navigation-timing/#obsolete">Navigation Timing Level 2 specification</a> 中已经被废弃,请使用 {{domxref("Performance.timeOrigin")}} 替代。</p> +</div> + +<p><code><strong>Performance</strong></code><strong><code>.timing</code></strong> 只读属性返回一个 {{domxref("PerformanceTiming")}} 对象,这个对象包括了页面相关的性能信息。</p> + +<h2 id="语法">语法</h2> + +<pre class="syntaxbox notranslate"><em>timingInfo</em> = <em>performance</em>.timing;</pre> + +<h2 id="规范">规范</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">规范名</th> + <th scope="col">状态</th> + <th scope="col">描述</th> + </tr> + <tr> + <td>{{SpecName('Navigation Timing', '#sec-window.performance-attribute', 'Performance.timing')}}</td> + <td>{{Spec2('Navigation Timing')}}</td> + <td>Initial definition</td> + </tr> + </tbody> +</table> + +<h2 id="浏览器兼容性">浏览器兼容性</h2> + +<p>{{Compat("api.Performance.timing")}}</p> + +<h2 id="相关">相关</h2> + +<ul> + <li>{{domxref("Performance")}} 接口.</li> +</ul> diff --git a/files/zh-cn/web/api/performance/tojson/index.html b/files/zh-cn/web/api/performance/tojson/index.html new file mode 100644 index 0000000000..df229b33cb --- /dev/null +++ b/files/zh-cn/web/api/performance/tojson/index.html @@ -0,0 +1,61 @@ +--- +title: Performance.toJSON() +slug: Web/API/Performance/toJSON +translation_of: Web/API/Performance/toJSON +--- +<div>{{APIRef("High Resolution Timing")}}</div> + +<div>{{domxref("Performance")}} 的 <strong><code>toJSON() 方法是一个标准的串行器:它返回一个由 performance 对象各个属性组成的 JSON</code></strong></div> + +<h2 id="Syntax">Syntax</h2> + +<pre class="syntaxbox">myPerf = performance.toJSON() +</pre> + +<h3 id="Arguments">Arguments</h3> + +<dl> + <dt>None</dt> + <dd> </dd> +</dl> + +<h3 id="Return_value">Return value</h3> + +<dl> + <dt>myPerf</dt> + <dd>{{domxref("Performance")}} 对象序列化之后转化成的 JSON 对象。</dd> +</dl> + +<h2 id="Example">Example</h2> + +<pre class="brush: js">var js; +js = window.performance.toJSON(); +console.log("json = " + JSON.stringify(js)); +</pre> + +<h2 id="Specifications">Specifications</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Specification</th> + <th scope="col">Status</th> + <th scope="col">Comment</th> + </tr> + <tr> + <td>{{SpecName('Highres Time Level 2', '#the-performance-interface', 'toJSON() serializer')}}</td> + <td>{{Spec2('Highres Time Level 2')}}</td> + <td>Defines <code>toJson()</code>.</td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility">Browser compatibility</h2> + +<div> +<div> + + +<p>{{Compat("api.Performance.toJSON")}}</p> +</div> +</div> diff --git a/files/zh-cn/web/api/performance/内存/index.html b/files/zh-cn/web/api/performance/内存/index.html new file mode 100644 index 0000000000..e9f5047d4e --- /dev/null +++ b/files/zh-cn/web/api/performance/内存/index.html @@ -0,0 +1,42 @@ +--- +title: Performance.memory +slug: Web/API/Performance/内存 +translation_of: Web/API/Performance/memory +--- +<p>{{APIRef}}</p> + +<h2 id="语法">语法</h2> + +<pre class="syntaxbox"><em>timingInfo</em> = <em>performance</em>.memory</pre> + +<h2 id="属性">属性</h2> + +<dl> + <dt><code>jsHeapSizeLimit</code></dt> + <dd>上下文内可用堆的最大体积,以字节计算。</dd> + <dt><code>totalJSHeapSize</code></dt> + <dd> 已分配的堆体积,以字节计算。</dd> +</dl> + +<dl> + <dt><code>usedJSHeapSize</code></dt> + <dd>当前 JS 堆活跃段(segment)的体积,以字节计算。</dd> +</dl> + +<h2 id="规范">规范</h2> + +<p>无。</p> + +<h2 id="浏览器兼容性">浏览器兼容性</h2> + +<div> + + +<p>{{Compat("api.Performance.memory")}}</p> +</div> + +<h2 id="查看更多">查看更多</h2> + +<ul> + <li>属于 {{domxref("Performance")}} 接口。</li> +</ul> |