aboutsummaryrefslogtreecommitdiff
path: root/files/zh-tw/web/api/performance/index.html
blob: 017efb71e173b53bb87d3af2bb84ef0c97a251b4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
---
title: Performance
slug: Web/API/Performance
tags:
  - API
  - Interface
  - Navigation Timing
  - NeedsTranslation
  - Performance
  - Reference
  - TopicStub
  - Web Performance
translation_of: Web/API/Performance
---
<div>{{APIRef("High Resolution Time")}}</div>

<p>The <strong><code>Performance</code></strong> interface provides access to performance-related information for the current page. It's part of the High Resolution Time API, but is enhanced by the <a href="/en-US/docs/Web/API/Performance_Timeline">Performance Timeline API</a>, the <a href="/en-US/docs/Web/API/Navigation_timing_API">Navigation Timing API</a>, the <a href="/en-US/docs/Web/API/User_Timing_API">User Timing API</a>, and the <a href="/en-US/docs/Web/API/Resource_Timing_API">Resource Timing API</a>.</p>

<p>An object of this type can be obtained by calling the {{domxref("Window.performance")}} read-only attribute.</p>

<div class="note">
<p><strong><em>Note</em>: </strong>This interface and its members are available in <a href="/en-US/docs/Web/API/Web_Workers_API">Web Workers</a>, except where indicated below. Also note that performance markers and measures are per context. If you create a mark on the main thread (or other worker), you cannot see it in a worker thread, and vice versa.</p>
</div>

<h2 id="Properties">Properties</h2>

<p><em>The <code>Performance</code> interface doesn't inherit any properties.</em></p>

<dl>
 <dt>{{deprecated_inline}} {{domxref("Performance.navigation")}} {{readonlyInline}}</dt>
 <dd>A {{domxref("PerformanceNavigation")}} object that provides useful context about the operations included in the times listed in <code>timing</code>, including whether the page was a load or a refresh, how many redirections occurred, and so forth.</dd>
 <dt>{{deprecated_inline}}  {{domxref("Performance.timing")}} {{readonlyInline}}</dt>
 <dd>A {{domxref("PerformanceTiming")}} object containing latency-related performance information. Not available in workers.</dd>
 <dt>{{domxref("Performance.memory", "performance.memory")}} {{Non-standard_inline}}</dt>
 <dd>A <em>non-standard</em> extension added in Chrome, this property provides an object with basic memory usage information. <em>You <strong>should not use</strong> this non-standard API.</em></dd>
 <dt>{{domxref("Performance.timeOrigin")}} {{readonlyInline}} {{Non-standard_inline}}</dt>
 <dd>Returns the high resolution timestamp of the start time of the performance measurement.</dd>
</dl>

<dl>
 <dt>
 <h3 id="Event_handlers">Event handlers</h3>
 </dt>
 <dt>{{domxref("Performance.onresourcetimingbufferfull")}}</dt>
 <dd>An {{domxref("EventTarget")}} which is a callback that will be called when the {{event("resourcetimingbufferfull")}} event is fired.</dd>
</dl>

<h2 id="Methods">Methods</h2>

<p><em><em>The <code>Performance</code> interface doesn't inherit any </em>methods</em>.</p>

<dl>
 <dt>{{domxref("Performance.clearMarks()")}}</dt>
 <dd>Removes the given <em>mark</em> from the browser's performance entry buffer.</dd>
 <dt>{{domxref("Performance.clearMeasures()")}}</dt>
 <dd>Removes the given <em>measure</em> from the browser's performance entry buffer.</dd>
 <dt>{{domxref("Performance.clearResourceTimings()")}}</dt>
 <dd>Removes all {{domxref("PerformanceEntry","performance entries")}} with a {{domxref("PerformanceEntry.entryType","entryType")}} of "<code>resource</code>" from the browser's performance data buffer.</dd>
 <dt>{{domxref("Performance.getEntries()")}}</dt>
 <dd>Returns a list of {{domxref("PerformanceEntry")}} objects based on the given <em>filter</em>.</dd>
 <dt>{{domxref("Performance.getEntriesByName()")}}</dt>
 <dd>Returns a list of {{domxref("PerformanceEntry")}} objects based on the given <em>name</em> and <em>entry type</em>.</dd>
 <dt>{{domxref("Performance.getEntriesByType()")}}</dt>
 <dd>Returns a list of {{domxref("PerformanceEntry")}} objects of the given <em>entry type</em>.</dd>
 <dt>{{domxref("Performance.mark()")}}</dt>
 <dd>Creates a {{domxref("DOMHighResTimeStamp","timestamp")}} in the browser's <em>performance entry buffer</em> with the given name.</dd>
 <dt>{{domxref("Performance.measure()")}}</dt>
 <dd>Creates a named {{domxref("DOMHighResTimeStamp","timestamp")}} in the browser's performance entry buffer between two specified marks (known as the <em>start mark</em> and <em>end mark</em>, respectively).</dd>
 <dt>{{domxref("Performance.now()")}}</dt>
 <dd>Returns a {{domxref("DOMHighResTimeStamp")}} representing the number of milliseconds elapsed since a reference instant.</dd>
 <dt>{{domxref("Performance.setResourceTimingBufferSize()")}}</dt>
 <dd>Sets the browser's resource timing buffer size to the specified number of "<code>resource</code>" {{domxref("PerformanceEntry.entryType","type")}} {{domxref("PerformanceEntry","performance entry")}} objects.</dd>
 <dt>{{domxref("Performance.toJSON()")}}</dt>
 <dd>Is a jsonizer returning a json object representing the <code>Performance</code> object.</dd>
</dl>

<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>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="Browser_compatibility">Browser compatibility</h2>

<div>


<p>{{Compat("api.Performance")}}</p>
</div>