Documentation/performance
namespace

performance

js/performance.js:101

WebAPI-style benchmarking API
For more information, see: https://developer.mozilla.org/en-US/docs/Web/API/Performance_API

propertyreadonly

timeOrigin

js/performance.js:211
timeOrigin: number = 0.0 };

Read-only property of the Performance interface returns the high resolution timestamp that is used as the baseline for performance-related timestamps.
In JSplitter context this value represents the "UNIX-time" (milliseconds since 1 January 1970) when script was loaded.

Default

0.0 };
method

clearMarks

js/performance.js:183
clearMarks(name)

Removes all or specific PerformanceEntry objects from the player's performance timeline.

Parameters

NameTypeDescription
name = ''optionalstring

A string representing the name of the PerformanceEntry object. If this argument is omitted, all entries with an entryType of "mark" will be removed.

method

clearMeasures

js/performance.js:189
clearMeasures(name)

Removes all or specific PerformanceEntry objects from the player's performance timeline.

Parameters

NameTypeDescription
name = ''optionalstring

A string representing the name of the PerformanceEntry object. If this argument is omitted, all entries with an entryType of "measure" will be removed.

method

getEntries

js/performance.js:159
getEntries()

Returns an array of all PerformanceEntry objects currently present in the performance timeline.
If you are only interested in performance entries of certain types ("mark" or "measure") or that have certain names, see getEntriesByType and getEntriesByName.

Returns

Array<PerformanceEntry>
method

getEntriesByName

js/performance.js:174
getEntriesByName(name, type)

Returns an array of PerformanceEntry objects currently present in the performance timeline with the given name and type ("mark" or "measure").
If you are interested in performance entries of certain types, see getEntriesByType. For all performance entries, see getEntries.

Parameters

NameTypeDescription
namestring

A string representing the name of the measure.

type = ''optionalstring

A string representing the name of the measure.

Returns

Array<PerformanceEntry>
method

getEntriesByType

js/performance.js:166
getEntriesByType(type)

Returns an array of PerformanceEntry objects currently present in the performance timeline for a given type ("mark" or "measure").
If you are interested in performance entries of certain name, see getEntriesByName. For all performance entries, see getEntries.

Parameters

NameTypeDescription
typestring

A string representing the name of the measure.

Returns

Array<PerformanceEntry>
method

mark

js/performance.js:122
mark(name, markOptions)

Creates a named PerformanceEntry object representing a high resolution timestamp marker in the player's performance timeline

Parameters

NameTypeDescription
namestring

A string representing the name of the mark.

markOptions = nulloptionalobject

An object for specifying a timestamp and additional metadata for the mark.
Consists of two optional properties:
detail: Arbitrary metadata to include in the mark. Defaults to null. Can be an object of any type
startTime: Value to use as the mark time. Defaults to performance.now()

Example

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');
const beginMark = performance.getEntriesByName('work-begin')[0];
console.log(`"${beginMark.detail.description}" started for id = ${beginMark.detail.id} executed in ${measure.duration} ms`);
performance.clearMarks();
performance.clearMeasures();
method

measure

js/performance.js:142
measure(measureName, startMark, endMark, measureOptions)

Creates a named PerformanceEntry object representing a time measurement between two marks in the player'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.
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()

Parameters

NameTypeDescription
measureNamestring

A string representing the name of the measure.

startMark = ''optionalstring

A string naming a PerformanceEntry with "mark" type in the performance timeline. The PerformanceEntry.startTime property of this mark will be used for calculating the measure.

endMark = ''optionalstring

A string naming a PerformanceEntry with "mark" type in the performance timeline. The PerformanceEntry.startTime property of this mark will be used for calculating the measure.

measureOptions = nulloptionalobject

An object for specifying a timestamp and additional metadata for the mark.
Consists of two optional properties:
detail: Arbitrary metadata to include in the mark. Defaults to null. Can be an object of any type
start: Value to use as the mark time. Defaults to performance.now()
duration: Value to use as the mark time. Defaults to performance.now()
end: Value to use as the mark time. Defaults to performance.now()

Returns

PerformanceEntry
method

now

js/performance.js:108
now()

Returns a high resolution timestamp in milliseconds with a fractional part. It represents the time elapsed since performance.timeOrigin (the time when script was loaded)
Unlike Date.now, the timestamps returned by performance.now() are not limited to one-millisecond resolution. Instead, they represent times as floating-point numbers with up to microsecond precision.
Also, Date.now() may have been impacted by system and user clock adjustments, clock skew, etc. as it is relative to the Unix epoch (1970-01-01T00:00:00Z) and dependent on the system clock.
The performance.now() method on the other hand is relative to the timeOrigin property which is a monotonic clock: its current time never decreases and isn't subject to adjustments.

Returns

number

Example

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

Observer

js/performance.js:202
Observer(callback)

Creates and returns a new PerformanceObserver object.

The observer callback is invoked when performance entry events are recorded by performance.mark() or performance.measure() calls for the entry types that have been registered, via the observe() method.

Parameters

NameTypeDescription
callbackfunction

Returns

PerformanceObserver
method

toString

js/performance.js:195
toString(measureName, startMark, endMark, measureOptions)

Returns string representation of Performance object.
This gives you a list of all performance entries in a human-readable form.

Returns

string