Documentation/performance
namespaceWORKER

performance

js/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

js/performance.js:320
timeOrigin: number = 0.0

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

methodWORKER

clearMarks

js/performance.js:286
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 performance.measure.

Parameters

NameTypeDescription
nameoptionalstring

Mark name to clear.

Returns

undefined
methodWORKER

clearMeasures

js/performance.js:295
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

js/performance.js:262
getEntries()

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

Returns

Array<PerformanceEntry>
methodWORKER

getEntriesByName

js/performance.js:277
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

js/performance.js:269
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

js/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 performance.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

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

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

Standard forms supported by JSplitter:
performance.measure(name) - measures from timestamp 0 to performance.now.
performance.measure(name, startMark) - measures from the most recent named start mark to now.
performance.measure(name, startMark, endMark) - measures between the most recent matching named marks.
performance.measure(name, options) - derives start/end times from PerformanceMeasureOptions.
performance.measure(name, {}, endMark) - measures from timestamp 0 to the named end mark.

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

js/performance.js:188
now()

Returns a monotonically increasing high-resolution timestamp in milliseconds relative to performance.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

js/performance.js:311
Observer(callback)

JSplitter compatibility factory that creates a PerformanceObserver.
New code may use the standard new PerformanceObserver(callback) form instead.

Parameters

NameTypeDescription
callbackPerformanceObserverCallback

Callback invoked when matching entries are delivered.

Returns

PerformanceObserver
methodWORKER

toString

js/performance.js:304
toString()

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

Returns

string