We're looking for a user researcher to understand the needs of developers and designers. Is this you or someone you know? Check out the post: https://mzl.la/2IGzdXS

PerformanceEntry

这篇翻译不完整。请帮忙从英语翻译这篇文章

The PerformanceEntry object encapsulates a single performance metric that is part of the performance timeline. A performance entry can be directly created by making a performance mark or measure (for example by calling the mark() method) at an explicit point in an application. Performance entries are also created in indirect ways such as loading a resource (such as an image).

Note: this interface is exposed to Window and Worker. It is extended by several interfaces including PerformanceMark, PerformanceMeasure, PerformanceFrameTiming, PerformanceNavigationTiming and PerformanceResourceTiming.

Properties

PerformanceEntry.name 只读
A DOMString representing the name of a performance entry when the metric was created.
PerformanceEntry.entryType 只读
A DOMString representing the type of performance metric such as "mark". See entryType for a list of valid values.
PerformanceEntry.startTime 只读
A DOMHighResTimeStamp representing the starting time for the performance metric.
PerformanceEntry.duration 只读
A DOMHighResTimeStamp representing the time value of the duration of the performance event.

Methods

PerformanceEntry.toJSON()
A jsonizer that returns a JSON representation of the PerformanceEntry object.

Example

The following example checks all PerformanceEntry properties to see if the browser supports them or not and if the browser does support the property, the property's value is written to the console.

function print_PerformanceEntries() {
  // Use getEntries() to get a list of all performance entries
  var p = performance.getEntries();
  for (var i=0; i < p.length; i++) {
    console.log("PerformanceEntry[" + i + "]");
    print_PerformanceEntry(p[i]);
  }
}
function print_PerformanceEntry(perfEntry) {
  var properties = ["name",
    "entryType",
    "startTime",
    "duration"];

  for (var i=0; i < properties.length; i++) {
    // check each property
    var supported = properties[i] in perfEntry;
    if (supported) {
      var value = perfEntry[properties[i]];
      console.log("... " + properties[i] + " = " + value);
    } else {
      console.log("... " + properties[i] + " = NOT supported");
    }
  }
}

Specifications

Specification Status Comment
Performance Timeline Level 2
PerformanceEntry
Candidate Recommendation Added toJSON() serializer method.
Performance Timeline
PerformanceEntry
Recommendation Initial 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. 25.0 webkit
46.0 (unprefixed)
(Yes) (Yes) (Yes) (Yes)
33 (unprefixed)
未实现
toJSON() method. (Yes) ? (Yes) 未实现 未实现 未实现
Feature Android Android Webview Edge Firefox Mobile (Gecko) Firefox OS IE Phone Opera Mobile Safari Mobile Chrome for Android
Basic support. (Yes) (Yes) webkit
46.0 (unprefixed)
(Yes) 25.0 (25.0) 1.2 (25.0) 10.0 (Yes)
33 (unprefixed)
未实现 (Yes) webkit
46.0 (unprefixed)
toJSON() method. (Yes) ? ? 25.0 (25.0) 1.2 (25.0) 未实现 (Yes) 未实现 ?

文档标签和贡献者

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