Documentation/performance
namespaceWORKER

performance

jsdoc/performance.js:178

High-resolution timing API implementing the JSplitter subset of the Web High Resolution Time, User Timing, and Performance Timeline APIs.
JSplitter currently records only user-created "mark" and "measure" entries; browser-specific navigation, resource, paint, and similar performance entry types are not available.
For the corresponding Web standards, see High Resolution Time, User Timing, and Performance Timeline.

Example source

propertyWORKERreadonly

timeOrigin

jsdoc/performance.js:325
timeOrigin: number = 0.0

Read-only Unix timestamp in milliseconds corresponding to the origin used by this performance timeline.
now values are measured relative to this origin.

methodWORKER

clearMarks

jsdoc/performance.js:291
clearMarks(name)

Removes mark entries from the performance timeline.
If name is supplied, all marks with that name are removed. If omitted, all mark entries are removed. Clearing a mark also removes it from subsequent named-mark lookup by measure.

Parameters

NameTypeDescription
nameoptionalstring

Mark name to clear.

Returns

undefined
methodWORKER

clearMeasures

jsdoc/performance.js:300
clearMeasures(name)

Removes measure entries from the performance timeline.
If name is supplied, all measures with that name are removed. If omitted, all measure entries are removed.

Parameters

NameTypeDescription
nameoptionalstring

Measure name to clear.

Returns

undefined
methodWORKER

getEntries

jsdoc/performance.js:267
getEntries()

Returns all PerformanceEntry objects currently stored in the performance timeline, ordered by startTime.

Returns

Array<PerformanceEntry>
methodWORKER

getEntriesByName

jsdoc/performance.js:282
getEntriesByName(name, type)

Returns timeline entries filtered by name and, optionally, entry type. Results are ordered by startTime.

Parameters

NameTypeDescription
namestring

Entry name.

typeoptionalstring

Optional entry type, for example "mark" or "measure".

Returns

Array<PerformanceEntry>
methodWORKER

getEntriesByType

jsdoc/performance.js:274
getEntriesByType(type)

Returns timeline entries filtered by entry type and ordered by startTime.

Parameters

NameTypeDescription
typestring

Entry type, for example "mark" or "measure".

Returns

Array<PerformanceEntry>
methodWORKER

mark

jsdoc/performance.js:201
mark(name, markOptions)

Creates a named PerformanceEntry with entryType "mark" and adds it to the performance timeline.
Multiple marks may use the same name. All marks remain in the timeline until cleared; when a mark name is later used by measure, the most recently created matching mark is used.

Parameters

NameTypeDescription
namestring

Mark name.

markOptionsoptionalPerformanceMarkOptions

Optional mark timestamp and metadata.

Returns

PerformanceEntry —

The created mark entry.

Throws

Error —

If startTime is not a finite non-negative number.

Example

const beginMark = performance.mark("work-begin", {
  detail: { description: "Begin of some important work", id: 777 }
});

doSomething();
performance.mark("work-end");

const measure = performance.measure("work-duration", "work-begin", "work-end");
console.log(`"${beginMark.detail.description}" for id=${beginMark.detail.id} took ${measure.duration} ms`);

performance.clearMarks();
performance.clearMeasures();
methodWORKER

measure

jsdoc/performance.js:226
measure(measureName, startOrMeasureOptions, endMark, legacyMeasureOptions)

Creates a named PerformanceEntry with entryType "measure" and adds it to the performance timeline.

Standard forms of measure supported by JSplitter:

performance.measure(name);                     // Timestamp 0 to performance.now().
performance.measure(name, startMark);          // Most recent start mark to now.
performance.measure(name, startMark, endMark); // Between the named marks.
performance.measure(name, options);            // Explicit start/end/duration options.
performance.measure(name, {}, endMark);        // Timestamp 0 to the named end mark.

See PerformanceMeasureOptions for the options object.

In options, start and end may be either mark names or finite non-negative timestamps. duration may be supplied with exactly one of start or end. If an explicitly named mark does not exist, an error is thrown.
Multiple measures may use the same name. Named mark lookup always uses the most recently created matching mark.

Compatibility note: for historical JSplitter compatibility, a fourth legacyMeasureOptions argument is also accepted. This form preserves the previous JSplitter precedence rules: existing explicit startMark/endMark values take precedence, while numeric start, end, or duration options fill missing values. New code should prefer the standard forms above.
For backward compatibility, an empty positional mark name ("") is treated as omitted rather than as a mark named with an empty string.

Parameters

NameTypeDescription
measureNamestring

Measure name.

startOrMeasureOptionsoptional(string|PerformanceMeasureOptions)

Start mark name or standard measure options.

endMarkoptionalstring

End mark name.

legacyMeasureOptionsoptionalObject

JSplitter legacy four-argument options object. Supports numeric start, end, duration, and arbitrary detail.

Returns

PerformanceEntry —

The created measure entry.

Throws

Error —

If a named mark cannot be resolved, a numeric timestamp/duration is invalid, or the standard options contain an invalid combination.

Example

performance.mark("work-start");
doSomething();
performance.mark("work-end");

const byMarks = performance.measure("work", "work-start", "work-end");
const byTimestamp = performance.measure("custom-range", { start: 10, duration: 25 });

console.log(byMarks.duration);
console.log(byTimestamp.duration);
methodWORKER

now

jsdoc/performance.js:188
now()

Returns a monotonically increasing high-resolution timestamp in milliseconds relative to timeOrigin. The value may contain a fractional part; actual resolution depends on the underlying system clock.
Unlike Date.now(), this timestamp is intended for measuring elapsed time and is not affected by wall-clock adjustments.

Returns

number

Example

const t0 = performance.now();
doSomething();
const t1 = performance.now();
console.log(`Call to doSomething took ${t1 - t0} milliseconds.`);
methodWORKER

Observer

jsdoc/performance.js:316
Observer(callback)

JSplitter compatibility factory that creates a PerformanceObserver.
New code may use the standard PerformanceObserver constructor with a callback argument instead.

Parameters

NameTypeDescription
callbackPerformanceObserverCallback

Callback invoked when matching entries are delivered.

Returns

PerformanceObserver
methodWORKER

toString

jsdoc/performance.js:309
toString()

JSplitter extension that returns a human-readable dump of the current performance timeline.

Returns

string