performance.measure() - Web APIs 编辑

The measure() method creates a named timestamp in the browser's performance entry buffer between marks, the navigation start time, or the current time. When measuring between two marks, there is a start mark and end mark, respectively. The named timestamp is referred to as a measure.

The measure can be retrieved by one of the Performance interfaces: (getEntries(), getEntriesByName() or getEntriesByType()).

The measure's performance entry will have the following property values:

Note:

This feature is available in Web Workers.

Syntax

performance.measure(name);
performance.measure(name, startMark);
performance.measure(name, startMark, endMark);
performance.measure(name, undefined, endMark);

Arguments

name
A DOMString representing the name of the measure.
startMark Optional
A DOMString representing the name of the measure's starting mark. May also be the name of a PerformanceTiming property. If it is omitted, then the start time will be the navigation start time.
endMark Optional
A DOMString representing the name of the measure's ending mark. May also be the name of a PerformanceTiming property. If it is omitted, then the current time is used.

Return value

void

Example

The following example shows how measure() is used to create a new measure performance entry in the browser's performance entry buffer.

const markerNameA = "example-marker-a"
const markerNameB = "example-marker-b"

// Run some nested timeouts, and create a PerformanceMark for each.
performance.mark(markerNameA);
setTimeout(function() {
  performance.mark(markerNameB);
  setTimeout(function() {

    // Create a variety of measurements.
    performance.measure("measure a to b", markerNameA, markerNameB);
    performance.measure("measure a to now", markerNameA);
    performance.measure("measure from navigation start to b", undefined, markerNameB);
    performance.measure("measure from the start of navigation to now");

    // Pull out all of the measurements.
    console.log(performance.getEntriesByType("measure"));

    // Finally, clean up the entries.
    performance.clearMarks();
    performance.clearMeasures();
  }, 1000);
}, 1000);

Specifications

SpecificationStatusComment
User Timing Level 2
The definition of 'measure()' in that specification.
Working DraftClarifies measure() processing model.
User Timing
The definition of 'measure()' in that specification.
RecommendationBasic definition.

Browser compatibility

BCD tables only load in the browser

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:134 次

字数:5718

最后编辑:7 年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文