User Timing

Editor’s Draft,

More details about this document
This version:
https://w3c.github.io/user-timing/
Latest published version:
https://www.w3.org/TR/user-timing/
Feedback:
[email protected] with subject line “[user-timing] … message topic …” (archives)
GitHub
Test Suite:
https://wpt.fyi/results/user-timing
Editor:
Nicolás Peña Moreno (Google)
Former Editors:
Ilya Grigorik (Google)
(Microsoft Corp.)
Zhiheng Wang (Google Inc.)
Anderson Quach (Microsoft Corp.)

Abstract

This specification defines an interface to help web developers measure the performance of their applications by giving them access to high precision timestamps.

Status of this document

This is a public copy of the editors’ draft. It is provided for discussion only and may change at any moment. Its publication here does not imply endorsement of its contents by W3C. Don’t cite this document other than as work in progress.

GitHub Issues are preferred for discussion of this specification.

This document is governed by the 18 August 2025 W3C Process Document.

This User Timing specification is intended to supersede [USER-TIMING-2] and includes:

1. Introduction

This section is non-normative.

Web developers need the ability to assess and understand the performance characteristics of their applications. While JavaScript [ECMA-262] provides a mechanism to measure application latency (retrieving the current timestamp from the Date.now() method), the precision of this timestamp varies between user agents.

This document defines the PerformanceMark and PerformanceMeasure interfaces, and extensions to the Performance interface, which expose a high precision, monotonically increasing timestamp so that developers can better measure the performance characteristics of their applications.

The following script shows how a developer can use the interfaces defined in this document to obtain timing data related to developer scripts.

async function run() {
  performance.mark("startTask1");
  await doTask1(); // Some developer code
  performance.mark("endTask1");

  performance.mark("startTask2");
  await doTask2(); // Some developer code
  performance.mark("endTask2");

  // Log them out
  const entries = performance.getEntriesByType("mark");
  for (const entry of entries) {
    console.table(entry.toJSON());
  }
}
run();

[PERFORMANCE-TIMELINE-2] defines two mechanisms that can be used to retrieve recorded metrics: getEntries() and getEntriesByType() methods, and the PerformanceObserver interface. The former is best suited for cases where you want to retrieve a particular metric by name at a single point in time, and the latter is optimized for cases where you may want to receive notifications of new metrics as they become available.

As another example, suppose that there is an element which, when clicked, fetches some new content and indicates that it has been fetched. We’d like to report the time from when the user clicked to when the fetch was complete. We can’t mark the time the click handler executes since that will miss latency to process the event, so instead we use the event hardware timestamp. We also want to know the name of the component to have more detailed analytics.

element.addEventListener("click", e => {
  const component = getComponent(element);
  fetch(component.url).then(() => {
    element.textContent = "Updated";
    const updateMark = performance.mark("update_component", {
      detail: {component: component.name},
    });
    performance.measure("click_to_update_component", {
      detail: {component: component.name},
      start: e.timeStamp,
      end: updateMark.startTime,
    });
  });
});

2. User Timing

2.1. Extensions to the Performance interface

The Performance interface and DOMHighResTimeStamp are defined in [HR-TIME-2]. The PerformanceEntry interface is defined in [PERFORMANCE-TIMELINE-2].

dictionary PerformanceMarkOptions {
    any detail;
    DOMHighResTimeStamp startTime;
};

dictionary PerformanceMeasureOptions {
    any detail;
    (DOMString or DOMHighResTimeStamp) start;
    DOMHighResTimeStamp duration;
    (DOMString or DOMHighResTimeStamp) end;
};

partial interface Performance {
    PerformanceMark mark(DOMString markName, optional PerformanceMarkOptions markOptions = {});
    undefined clearMarks(optional DOMString markName);
    PerformanceMeasure measure(DOMString measureName, optional (DOMString or PerformanceMeasureOptions) startOrMeasureOptions = {}, optional DOMString endMark);
    undefined clearMeasures(optional DOMString measureName);
};

2.1.1. mark() method

Stores a timestamp with the associated name (a "mark"). It MUST run these steps:

  1. Run the PerformanceMark constructor and let entry be the newly created object.
  2. Queue a PerformanceEntry entry.
  3. Add entry to the performance entry buffer.
  4. Return entry.
2.1.1.1. PerformanceMarkOptions dictionary
detail
Metadata to be included in the mark.
startTime
Timestamp to be used as the mark time.

2.1.2. clearMarks() method

Removes the stored timestamp with the associated name. It MUST run these steps:

  1. If markName is omitted, remove all PerformanceMark objects from the performance entry buffer.
  2. Otherwise, remove all PerformanceMark objects listed in the performance entry buffer whose name is markName.
  3. Return undefined.

2.1.3. measure() method

Stores the DOMHighResTimeStamp duration between two marks along with the associated name (a "measure"). It MUST run these steps:

  1. If startOrMeasureOptions is a PerformanceMeasureOptions object and at least one of start, end, duration, and detail exist, run the following checks:
    1. If endMark is given, throw a TypeError.
    2. If startOrMeasureOptions’s start and end members are both omitted, throw a TypeError.
    3. If startOrMeasureOptions’s start, duration, and end members all exist, throw a TypeError.
  2. Compute end time as follows:
    1. If endMark is given, let end time be the value returned by running the convert a mark to a timestamp algorithm passing in endMark.
    2. Otherwise, if startOrMeasureOptions is a PerformanceMeasureOptions object, and if its end member exists, let end time be the value returned by running the convert a mark to a timestamp algorithm passing in startOrMeasureOptions’s end.
    3. Otherwise, if startOrMeasureOptions is a PerformanceMeasureOptions object, and if its start and duration members both exist:
      1. Let start be the value returned by running the convert a mark to a timestamp algorithm passing in start.
      2. Let duration be the value returned by running the convert a mark to a timestamp algorithm passing in duration.
      3. Let end time be start plus duration.
    4. Otherwise, let end time be the value that would be returned by the Performance object’s now() method.
  3. Compute start time as follows:
    1. If startOrMeasureOptions is a PerformanceMeasureOptions object, and if its start member exists, let start time be the value returned by running the convert a mark to a timestamp algorithm passing in startOrMeasureOptions’s start.
    2. Otherwise, if startOrMeasureOptions is a PerformanceMeasureOptions object, and if its duration and end members both exist:
      1. Let duration be the value returned by running the convert a mark to a timestamp algorithm passing in duration.
      2. Let end be the value returned by running the convert a mark to a timestamp algorithm passing in end.
      3. Let start time be end minus duration.
    3. Otherwise, if startOrMeasureOptions is a DOMString, let start time be the value returned by running the convert a mark to a timestamp algorithm passing in startOrMeasureOptions.
    4. Otherwise, let start time be 0.
  4. Create a new PerformanceMeasure object (entry) with this’s relevant realm.
  5. Set entry’s name attribute to measureName.
  6. Set entry’s entryType attribute to DOMString "measure".
  7. Set entry’s startTime attribute to start time.
  8. Set entry’s duration attribute to the duration from start time to end time. The resulting duration value MAY be negative.
  9. Set entry’s detail attribute as follows:
    1. If startOrMeasureOptions is a PerformanceMeasureOptions object and startOrMeasureOptions’s detail member exists:
      1. Let record be the result of calling the StructuredSerialize algorithm on startOrMeasureOptions’s detail.
      2. Set entry’s detail to the result of calling the StructuredDeserialize algorithm on record and the current realm.
    2. Otherwise, set it to null.
  10. Queue a PerformanceEntry entry.
  11. Add entry to the performance entry buffer.
  12. Return entry.
2.1.3.1. PerformanceMeasureOptions dictionary
detail
Metadata to be included in the measure.
start
Timestamp to be used as the start time or string to be used as start mark.
duration
Duration between the start and end times.
end
Timestamp to be used as the end time or string to be used as end mark.

2.1.4. clearMeasures() method

Removes stored timestamp with the associated name. It MUST run these steps:

  1. If measureName is omitted, remove all PerformanceMeasure objects in the performance entry buffer.
  2. Otherwise remove all PerformanceMeasure objects listed in the performance entry buffer whose name is measureName.
  3. Return undefined.

2.2. The PerformanceMark Interface

The PerformanceMark interface also exposes marks created via the Performance interface’s mark() method to the Performance Timeline.

[Exposed=(Window,Worker)]
interface PerformanceMark : PerformanceEntry {
  constructor(DOMString markName, optional PerformanceMarkOptions markOptions = {});
  readonly attribute any detail;
};

The PerformanceMark interface extends the following attributes of the PerformanceEntry interface:

The name attribute must return the mark’s name.

The entryType attribute must return the DOMString "mark".

The startTime attribute must return a DOMHighResTimeStamp with the mark’s time value.

The duration attribute must return a DOMHighResTimeStamp of value 0.

The PerformanceMark interface contains the following additional attribute:

The detail attribute must return the value it is set to (it’s copied from the PerformanceMarkOptions dictionary).

2.2.1. The PerformanceMark Constructor

The PerformanceMark constructor must run the following steps:

  1. If the current global object is a Window object and markName uses the same name as a read only attribute in the PerformanceTiming interface, throw a SyntaxError.
  2. Create a new PerformanceMark object (entry) with the current global object’s realm.
  3. Set entry’s name attribute to markName.
  4. Set entry’s entryType attribute to DOMString "mark".
  5. Set entry’s startTime attribute as follows:
    1. If markOptions’s startTime member exists, then:
      1. If markOptions’s startTime is negative, throw a TypeError.
      2. Otherwise, set entry’s startTime to the value of markOptions’s startTime.
    2. Otherwise, set it to the value that would be returned by the Performance object’s now() method.
  6. Set entry’s duration attribute to 0.
  7. If markOptions’s detail is null, set entry’s detail to null.
  8. Otherwise:
    1. Let record be the result of calling the StructuredSerialize algorithm on markOptions’s detail.
    2. Set entry’s detail to the result of calling the StructuredDeserialize algorithm on record and the current realm.

2.3. The PerformanceMeasure Interface

The PerformanceMeasure interface also exposes measures created via the Performance interface’s measure() method to the Performance Timeline.

[Exposed=(Window,Worker)]
interface PerformanceMeasure : PerformanceEntry {
  readonly attribute any detail;
};

The PerformanceMeasure interface extends the following attributes of the PerformanceEntry interface:

The name attribute must return the measure’s name.

The entryType attribute must return the DOMString "measure".

The startTime attribute must return a DOMHighResTimeStamp with the measure’s start mark.

The duration attribute must return a DOMHighResTimeStamp with the duration of the measure.

The PerformanceMeasure interface contains the following additional attribute:

The detail attribute must return the value it is set to (it’s copied from the PerformanceMeasureOptions dictionary).

3. Processing

A user agent implementing the User Timing API would need to include "mark" and "measure" in supportedEntryTypes. This allows developers to detect support for User Timing.

3.1. Convert a mark to a timestamp

To convert a mark to a timestamp, given a mark that is a DOMString or DOMHighResTimeStamp run these steps:

  1. If mark is a DOMString and it has the same name as a read only attribute in the PerformanceTiming interface, let end time be the value returned by running the convert a name to a timestamp algorithm with name set to the value of mark.
  2. Otherwise, if mark is a DOMString, let end time be the value of the startTime attribute from the most recent occurrence of a PerformanceMark object in the performance entry buffer whose name is mark. If no matching entry is found, throw a SyntaxError.
  3. Otherwise, if mark is a DOMHighResTimeStamp:
    1. If mark is negative, throw a TypeError.
    2. Otherwise, let end time be mark.

3.2. Convert a name to a timestamp

To convert a name to a timestamp given a name that is a read only attribute in the PerformanceTiming interface, run these steps:

  1. If the global object is not a Window object, throw a TypeError.
  2. If name is navigationStart, return 0.
  3. Let startTime be the value of navigationStart in the PerformanceTiming interface.
  4. Let endTime be the value of name in the PerformanceTiming interface.
  5. If endTime is 0, throw an InvalidAccessError.
  6. Return result of subtracting startTime from endTime.

The PerformanceTiming interface was defined in [NAVIGATION-TIMING] and is now considered obsolete. The use of names from the PerformanceTiming interface is supported to remain backwards compatible, but there are no plans to extend this functionality to names in the PerformanceNavigationTiming interface defined in [NAVIGATION-TIMING-2] (or other interfaces) in the future.

Developers are encouraged to use the following recommended mark names to mark common timings. The user agent does not validate that the usage of these names is appropriate or consistent with its description.

Adding such recommended mark names can help performance tools tailor guidance to a site. These mark names can also help real user monitoring providers and user agents collect web developer signals regarding their application’s performance at scale, and surface this information to developers without requiring any site-specific work.

"mark_fully_loaded"
The time when the page is considered fully loaded as marked by the developer in their application.

In this example, the page asynchonously initializes a chat widget, a searchbox, and a newsfeed upon loading. When finished, the "mark_fully_loaded" mark name enables lab tools and analytics providers to automatically show the timing.

window.addEventListener("load", (event) => {
  Promise.all([
    loadChatWidget(),
    initializeSearchAutocomplete(),
    initializeNewsfeed()]).then(() => {
      performance.mark('mark_fully_loaded');
  });
});
"mark_fully_visible"
The time when the page is considered fully visible to an end-user as marked by the developer in their application.
"mark_interactive"
The time when the page is considered interactive to an end-user as marked by the developer in their application.
"mark_feature_usage"
Mark the usage of a feature which may impact performance so that tooling and analytics can take it into account. The detail metadata can contain any useful information about the feature, including:
feature
The name of the feature used.
framework
If applicable, the underlying framework the feature is intended for, such as a JavaScript framework, content management system, or e-commerce platform.

In this example, the ImageOptimizationComponent for FancyJavaScriptFramework is used to size images for optimal performance. The code notes this feature’s usage so that lab tools and analytics can measure whether it helped improve performance.

performance.mark('mark_feature_usage', {
  'detail': {
    'feature': 'ImageOptimizationComponent',
    'framework': 'FancyJavaScriptFramework'
  }
})

5. Privacy and Security

This section is non-normative.

The interfaces defined in this specification expose potentially sensitive timing information on specific JavaScript activity of a page. Please refer to [HR-TIME-2] for privacy and security considerations of exposing high-resolution timing information.

Because the web platform has been designed with the invariant that any script included on a page has the same access as any other script included on the same page, regardless of the origin of either scripts, the interfaces defined by this specification do not place any restrictions on recording or retrieval of recorded timing information - i.e. a user timing mark or measure recorded by any script included on the page can be read by any other script running on the same page, regardless of origin.

Acknowledgments

Thanks to James Simonsen, Jason Weber, Nic Jansma, Philippe Le Hegaret, Karen Anderson, Steve Souders, Sigbjorn Vik, Todd Reifsteck, and Tony Gentilcore for their contributions to this work.

Conformance

Document conventions

Conformance requirements are expressed with a combination of descriptive assertions and RFC 2119 terminology. The key words “MUST”, “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”, “SHOULD NOT”, “RECOMMENDED”, “MAY”, and “OPTIONAL” in the normative parts of this document are to be interpreted as described in RFC 2119. However, for readability, these words do not appear in all uppercase letters in this specification.

All of the text of this specification is normative except sections explicitly marked as non-normative, examples, and notes. [RFC2119]

Examples in this specification are introduced with the words “for example” or are set apart from the normative text with class="example", like this:

This is an example of an informative example.

Informative notes begin with the word “Note” and are set apart from the normative text with class="note", like this:

Note, this is an informative note.

Conformant Algorithms

Requirements phrased in the imperative as part of algorithms (such as "strip any leading space characters" or "return false and abort these steps") are to be interpreted with the meaning of the key word ("must", "should", "may", etc) used in introducing the algorithm.

Conformance requirements phrased as algorithms or specific steps can be implemented in any manner, so long as the end result is equivalent. In particular, the algorithms defined in this specification are intended to be easy to understand and are not intended to be performant. Implementers are encouraged to optimize.

Index

Terms defined by this specification

Terms defined by reference

References

Normative References

[HR-TIME-2]
Ilya Grigorik. High Resolution Time Level 2. URL: https://w3c.github.io/hr-time/
[HR-TIME-3]
Yoav Weiss. High Resolution Time. URL: https://w3c.github.io/hr-time/
[HTML]
Anne van Kesteren; et al. HTML Standard. Living Standard. URL: https://html.spec.whatwg.org/multipage/
[INFRA]
Anne van Kesteren; Domenic Denicola. Infra Standard. Living Standard. URL: https://infra.spec.whatwg.org/
[NAVIGATION-TIMING-2]
Yoav Weiss; Noam Rosenthal. Navigation Timing Level 2. URL: https://w3c.github.io/navigation-timing/
[PERFORMANCE-TIMELINE-2]
Nicolas Pena Moreno. Performance Timeline. URL: https://w3c.github.io/performance-timeline/
[RFC2119]
S. Bradner. Key words for use in RFCs to Indicate Requirement Levels. March 1997. Best Current Practice. URL: https://datatracker.ietf.org/doc/html/rfc2119
[WEBIDL]
Edgar Chen; Timothy Gu. Web IDL Standard. Living Standard. URL: https://webidl.spec.whatwg.org/

Informative References

[ECMA-262]
ECMAScript Language Specification. URL: https://tc39.es/ecma262/multipage/
[NAVIGATION-TIMING]
Zhiheng Wang. Navigation Timing. 17 December 2012. REC. URL: https://www.w3.org/TR/navigation-timing/
[USER-TIMING-2]
Ilya Grigorik. User Timing Level 2. URL: https://w3c.github.io/user-timing/

IDL Index

dictionary PerformanceMarkOptions {
    any detail;
    DOMHighResTimeStamp startTime;
};

dictionary PerformanceMeasureOptions {
    any detail;
    (DOMString or DOMHighResTimeStamp) start;
    DOMHighResTimeStamp duration;
    (DOMString or DOMHighResTimeStamp) end;
};

partial interface Performance {
    PerformanceMark mark(DOMString markName, optional PerformanceMarkOptions markOptions = {});
    undefined clearMarks(optional DOMString markName);
    PerformanceMeasure measure(DOMString measureName, optional (DOMString or PerformanceMeasureOptions) startOrMeasureOptions = {}, optional DOMString endMark);
    undefined clearMeasures(optional DOMString measureName);
};

[Exposed=(Window,Worker)]
interface PerformanceMark : PerformanceEntry {
  constructor(DOMString markName, optional PerformanceMarkOptions markOptions = {});
  readonly attribute any detail;
};

[Exposed=(Window,Worker)]
interface PerformanceMeasure : PerformanceEntry {
  readonly attribute any detail;
};

MDN

Performance/clearMarks

In all current engines.

Firefox38+Safari11+Chrome29+
Opera33+Edge79+
Edge (Legacy)12+IE10+
Firefox for Android42+iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile33+
Node.js8.5.0+
MDN

Performance/clearMeasures

In all current engines.

Firefox38+Safari11+Chrome29+
Opera33+Edge79+
Edge (Legacy)12+IE10+
Firefox for Android42+iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile33+
Node.js16.7.0+
MDN

Performance/mark

In all current engines.

Firefox38+Safari11+Chrome28+
Opera33+Edge79+
Edge (Legacy)12+IE10+
Firefox for Android42+iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile33+
Node.js8.5.0+
MDN

Performance/measure

In all current engines.

Firefox38+Safari11+Chrome28+
Opera33+Edge79+
Edge (Legacy)12+IE10+
Firefox for Android42+iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile33+
Node.js8.5.0+
MDN

Performance

In all current engines.

Firefox7+Safari8+Chrome6+
Opera?Edge79+
Edge (Legacy)12+IE9+
Firefox for Android?iOS Safari9+Chrome for Android?Android WebView37+Samsung Internet?Opera Mobile?
Node.jsNone
MDN

PerformanceMark/PerformanceMark

In all current engines.

Firefox101+Safari14.1+Chrome76+
Opera?Edge79+
Edge (Legacy)?IENone
Firefox for Android?iOS Safari?Chrome for Android?Android WebView79+Samsung Internet?Opera Mobile?
Node.js16.0.0+
MDN

PerformanceMark/detail

In all current engines.

Firefox101+Safari14.1+Chrome78+
Opera?Edge79+
Edge (Legacy)?IENone
Firefox for Android?iOS Safari?Chrome for Android?Android WebView79+Samsung Internet?Opera Mobile?
Node.js16.0.0+
MDN

PerformanceMark

In all current engines.

Firefox38+Safari11+Chrome28+
Opera?Edge79+
Edge (Legacy)12+IE10+
Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile14+
Node.js8.5.0+
MDN

PerformanceMeasure/detail

In all current engines.

Firefox103+Safari14.1+Chrome78+
Opera?Edge79+
Edge (Legacy)?IENone
Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?
Node.js16.0.0+
MDN

PerformanceMeasure

In all current engines.

Firefox38+Safari11+Chrome25+
Opera33+Edge79+
Edge (Legacy)12+IE10+
Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile33+
Node.js8.5.0+