Performance.mark()

翻译正在进行中。

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 performance entry will have the following property values:

If the name given to this method already exists in the PerformanceTiming interface, SyntaxError is thrown.

Syntax

performance.mark(name);

Arguments

name
A DOMString representing the name of the mark.

Return value

void
 

Example

The following example shows how mark() is used to create an application-defined peformance entry in the browser's performance entry buffer.

function create_mark(name) {
  if (performance.mark === undefined) {
    console.log("performance.mark Not supported");
    return;
  }
  // Create the performance mark
  performance.mark(name);
  // mark 方法是可以创建多条同名 performanceEntry 的,例如:
  // performance.mark("begin")
  // performance.mark("begin")
  // performance.mark("begin")
  // performance.mark("begin")
  // performance.getEntriesByName("begin")
  //    [...]
  //        0: PerformanceMark { name: "begin", entryType: "mark", startTime: 94661370.14, … }
  //        ​1: PerformanceMark { name: "begin", entryType: "mark", startTime: 95542853.4, … }​
  //        2: PerformanceMark { name: "begin", entryType: "mark", startTime: 95545560.92, … }​
  //        3: PerformanceMark { name: "begin", entryType: "mark", startTime: 95548089.94, … }​
  //        length: 4​
  //        __proto__: Array [] 
}

Specifications

Specification Status Comment
User Timing Level 2
mark()
Working Draft Clarifies mark() processing model.
User Timing
mark()
Recommendation Basic definition.

Browser compatibility

We're converting our compatibility data into a machine-readable JSON format. This compatibility table still uses the old format, because we haven't yet converted the data it contains. Find out how you can help!

Feature Chrome Edge Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic Support 43.0 (Yes) 41 10 33 未实现
Feature Android Android Webview Edge Firefox Mobile (Gecko) Firefox OS IE Phone Opera Mobile Safari Mobile Chrome for Android
Basic Support 未实现 46.0 (Yes) 42 42 10 33 未实现 46.0

文档标签和贡献者

 此页面的贡献者: ihgazni2
 最后编辑者: ihgazni2,