performance.mark() - Web APIs 编辑
The mark()
method creates a timestamp
in the browser's performance entry buffer with the given name.
The application defined timestamp can be retrieved by one of the Performance
interface's getEntries*()
methods (getEntries()
, getEntriesByName()
or getEntriesByType()
).
The mark()'s
stores its data internally as PerformanceEntry
.
Note:
This feature is available in Web Workers.Syntax
performance.mark(name);
Arguments
- name
- A
DOMString
representing the name of the mark. If thename
given to this method already exists in thePerformanceTiming
interface,SyntaxError
is thrown.
Return value
- void
Example
The following example shows how to use mark()
to create and retrieve PerformanceMark
entries.
// Create a bunch of marks.
performance.mark("squirrel");
performance.mark("squirrel");
performance.mark("monkey");
performance.mark("monkey");
performance.mark("dog");
performance.mark("dog");
// Get all of the PerformanceMark entries.
const allEntries = performance.getEntriesByType("mark");
console.log(allEntries.length);
// 6
// Get all of the "monkey" PerformanceMark entries.
const monkeyEntries = performance.getEntriesByName("monkey");
console.log(monkeyEntries.length);
// 2
// Clear out all of the marks.
performance.clearMarks();
Specifications
Specification | Status | Comment |
---|---|---|
User Timing Level 2 The definition of 'mark()' in that specification. | Working Draft | Clarifies mark() processing model. |
User Timing The definition of 'mark()' in that specification. | Recommendation | Basic definition. |
Browser compatibility
BCD tables only load in the browser
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论