This feature is well established and works across many devices and browser versions. It’s been available across browsers since September 2017.
Note: This feature is available in Web Workers.
The measure() method creates a named PerformanceMeasure object representing a time measurement between two marks in the browser's performance timeline.
When measuring between two marks, there is a start mark and end mark, respectively. The named timestamp is referred to as a measure.
measure(measureName) measure(measureName, startMark) measure(measureName, startMark, endMark) measure(measureName, measureOptions) measure(measureName, measureOptions, endMark)
If only measureName is specified, the start timestamp is set to zero, and the end timestamp (which is used to calculate the duration) is the value that would be returned by Performance.now().
You can use strings to identify PerformanceMark objects as start and end marks.
To only provide an endMark, you need to provide an empty measureOptions object: performance.measure("myMeasure", {}, "myEndMarker").
measureNameA string representing the name of the measure.
measureOptions OptionalAn object that may contain measure options.
detail OptionalArbitrary metadata to be included in the measure. Defaults to null. Must be structured-cloneable.
start OptionalTimestamp (DOMHighResTimeStamp) to be used as the start time, or string that names a PerformanceMark to use for the start time.
If this is a string naming a PerformanceMark, then it is defined in the same way as startMark.
duration OptionalDuration (in milliseconds) between the start and end mark times. If omitted, this defaults to performance.now(); the time that has elapsed since the context was created. If provided, you must also specify either start or end but not both.
end OptionalTimestamp (DOMHighResTimeStamp) to be used as the end time, or string that names a PerformanceMark to use for the end time.
If this is a string naming a PerformanceMark, then it is defined in the same way as endMark.
startMark OptionalA string naming a PerformanceMark in the performance timeline. The PerformanceEntry.startTime property of this mark will be used for calculating the measure.
endMark OptionalA string naming a PerformanceMark in the performance timeline. The PerformanceEntry.startTime property of this mark will be used for calculating the measure. If you want to pass this argument, you must also pass either startMark or an empty measureOptions object.
The PerformanceMeasure entry that was created.
The returned measure will have the following property values:
entryType - set to "measure".
name - set to the name argument.
startTime - set to:
timestamp, if specified in measureOptions.start.timestamp of a start mark, if specified in measureOptions.start or startMark
measureOptions.end and measureOptions.duration (if measureOptions.start was not specified)duration - set to a DOMHighResTimeStamp that is the duration of the measure calculated by subtracting the startTime from the end timestamp.
The end timestamp is one of:
timestamp, if specified in measureOptions.end.timestamp of an end mark, if one is specified in measureOptions.end or endMark
measureOptions.start and measureOptions.duration (if measureOptions.end was not specified)Performance.now(), if no end mark is specified or can be determined from other values.detail - set to the value passed in measureOptions.
TypeErrorThis can be thrown in any case where the start, end or duration might be ambiguous:
endMark and measureOptions are specified.measureOptions is specified with duration but without specifying either start or end.measureOptions is specified with all of start, end, and duration.SyntaxError DOMException
The named mark does not exist.
endMark or measureOptions.end, but there is no PerformanceMark in the performance buffer with the matching name.endMark or measureOptions.end, but it cannot be converted to match that of a read only attribute in the PerformanceTiming interface.startMark or measureOptions.start, but there is no PerformanceMark in the performance buffer with the matching name.startMark or measureOptions.start, but it cannot be converted to match that of a read only attribute in the PerformanceTiming interface.DataCloneError DOMException
The measureOptions.detail value is non-null and cannot be serialized using the HTML "StructuredSerialize" algorithm.
RangeErrorThe measureOptions.detail value is non-null and memory cannot be allocated during serialization using the HTML "StructuredSerialize" algorithm.
Given two of your own markers "login-started" and "login-finished", you can create a measurement called "login-duration" as shown in the following example. The returned PerformanceMeasure object will then provide a duration property to tell you the elapsed time between the two markers.
const loginMeasure = performance.measure( "login-duration", "login-started", "login-finished", ); console.log(loginMeasure.duration);
To do more advanced measurements, you can pass a measureOptions parameter. For example, you can use the event.timeStamp property from a click event as the start time.
performance.measure("login-click", {
start: myClickEvent.timeStamp,
end: myMarker.startTime,
});
You can use the details property to provide additional information of any type. Maybe you want to record which HTML element was clicked, for example.
performance.measure("login-click", {
detail: { htmlElement: myElement.id },
start: myClickEvent.timeStamp,
end: myMarker.startTime,
});
| Specification |
|---|
| User Timing> # dom-performance-measure> |
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | |
measure |
2825–28 | 12 | 38 | 33 | 11 | 2825–28 | 42 | 33 | 11 | 1.5 | 4.4 | 11 |
measureOptions_parameter |
77 | 79 | 103 | 64 | 14.1 | 77 | 103 | 55 | 14.5 | 12.0 | 77 | 14.5 |
returns_performancemeasure |
78 | 79 | 103 | 65 | 14.1 | 78 | 103 | 56 | 14.5 | 12.0 | 78 | 14.5 |
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/Performance/measure