aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/performance/measure/index.html
diff options
context:
space:
mode:
Diffstat (limited to 'files/zh-cn/web/api/performance/measure/index.html')
-rw-r--r--files/zh-cn/web/api/performance/measure/index.html108
1 files changed, 108 insertions, 0 deletions
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>