This page is Ready to Use

Notice: The WebPlatform project, supported by various stewards between 2012 and 2015, has been discontinued. This site is now available on github.

measure

Summary

Stores the DOMHighResTimeStamp duration between two marks along with the associated name (a “measure”).

Method of apis/user_timing/Performanceapis/user_timing/Performance

Syntax

 object.measure(name, startMark, endMark);

Parameters

name

Data-type
any

Name associated with the performance measure.

startMark

Data-type
any

(Optional)

Name of the start performance mark.

endMark

Data-type
any

(Optional)

Name of the end performance mark.

Return Value

No return value

Examples

// set begin mark
performance.mark("startMark");
// execute a function to be measured
someFunction();
// set end mark
performance.mark("stopMark");

// save the timing information
performance.measure("functionTime", "startMark", "stopMark");
// display the measured time
var measures = performance.getEntriesByType("measure");
alert("functionTime: " + measures[0].duration);

// clear the measure "functionTime"
performance.clearMeasures("functionTime");
// clear all marks
performance.clearMarks();

Notes

  • If neither the startMark nor the endMark argument is specified, measure() will store the duration as a DOMHighResTimeStamp from navigationStart to the current time.
  • If the startMark argument is specified, but the endMark argument is not specified, measure() will store the duration as a DOMHighResTimeStamp from the most recent occurrence of the start mark to the current time.
  • If both the startMark and endMark arguments are specified, measure() will store the duration as a DOMHighResTimeStamp from the most recent occurrence of the start mark to the most recent occurrence of the end mark.

Related specifications

W3C User Timing Specification
W3C Recommendation

Attributions