performance.mark()

The mark() method creates a timestamp in the browser's performance entry buffer with the given name.

The application defined timestamp can also be retrieved by one of the Performance interface's getEntries*() methods (getEntries(), getEntriesByName() or getEntriesByType()).

The mark()'s stores its data internally as PerformanceEntry.

Note: This feature is available in Web Workers

Syntax

performance.mark(name);

Arguments

name

A DOMString representing the name of the mark. If the name given to this method already exists in the PerformanceTiming interface, SyntaxError is thrown.

Return value

entry

The PerformanceMark entry that was created.

Example

The following example shows how to use mark() to create and retrieve PerformanceMark entries.

// Create a bunch of marks.
performance.mark("squirrel");
performance.mark("squirrel");
performance.mark("monkey");
performance.mark("monkey");
performance.mark("dog");
performance.mark("dog");

// Get all of the PerformanceMark entries.
const allEntries = performance.getEntriesByType("mark");
console.log(allEntries.length);
// 6

// Get all of the "monkey" PerformanceMark entries.
const monkeyEntries = performance.getEntriesByName("monkey");
console.log(monkeyEntries.length);
// 2

// Clear out all of the marks.
performance.clearMarks();

Specifications

Browser compatibility

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari WebView Android Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet
mark
28
25-28
12
41
10
33
11
≤37
28
25-28
42
33
11
1.5

© 2005–2021 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/Performance/mark