Skip to content

Performance

[<Interface>]
type Performance =
    abstract member eventLoopUtilization: EventLoopUtilityFunction with get, set
    abstract member nodeTiming: PerformanceNodeTiming
    abstract member timeOrigin: float
    abstract member clearMarks (?name: string) : unit
    abstract member clearMeasures (?name: string) : unit
    abstract member clearResourceTimings (?name: string) : unit
    abstract member getEntries () : PerformanceEntry array
    abstract member getEntriesByName (name: string, ?type: EntryType) : PerformanceEntry array
    abstract member getEntriesByType (type: EntryType) : PerformanceEntry array
    abstract member mark (name: string, ?options: MarkOptions) : PerformanceMark
    abstract member markResourceTiming (timingInfo: obj, requestedUrl: string, initiatorType: string, global: obj, cacheMode: CacheMode, bodyInfo: obj, responseStatus: float, ?deliveryType: string) : PerformanceResourceTiming
    abstract member measure (name: string, options: MeasureOptions) : PerformanceMeasure
    abstract member measure (name: string, ?startMark: string, ?endMark: string) : PerformanceMeasure
    abstract member now () : float
    abstract member setResourceTimingBufferSize (maxSize: float) : unit
    abstract member timerify<'T> (fn: 'T, ?options: TimerifyOptions) : 'T
    abstract member toJSON () : obj
AssemblyXantham.Fable.Node

Declared inside

MarkResourceTiming

Properties

abstract member eventLoopUtilization: EventLoopUtilityFunction with get, set

eventLoopUtilization is similar to CPU utilization except that it is calculated using high precision wall-clock time. It represents the percentage of time the event loop has spent outside the event loop's event provider (e.g. epoll_wait). No other CPU idle time is taken into consideration.

abstract member nodeTiming: PerformanceNodeTiming

This property is an extension by Node.js. It is not available in Web browsers.

An instance of the PerformanceNodeTiming class that provides performance metrics for specific Node.js operational milestones.

@since v8.5.0

abstract member timeOrigin: float

The timeOrigin specifies the high resolution millisecond timestamp at which the current node process began, measured in Unix time.

@since v8.5.0

Methods

abstract member clearMarks (?name: string) : unit

If name is not provided, removes all PerformanceMark objects from the Performance Timeline. If name is provided, removes only the named mark.

@since v8.5.0

abstract member clearMeasures (?name: string) : unit

If name is not provided, removes all PerformanceMeasure objects from the Performance Timeline. If name is provided, removes only the named measure.

@since v16.7.0

abstract member clearResourceTimings (?name: string) : unit

If name is not provided, removes all PerformanceResourceTiming objects from the Resource Timeline. If name is provided, removes only the named resource.

@since v18.2.0, v16.17.0

abstract member getEntries () : PerformanceEntry array

Returns a list of PerformanceEntry objects in chronological order with respect to performanceEntry.startTime. If you are only interested in performance entries of certain types or that have certain names, see performance.getEntriesByType() and performance.getEntriesByName().

@since v16.7.0

abstract member getEntriesByName (name: string, ?type: EntryType) : PerformanceEntry array

Returns a list of PerformanceEntry objects in chronological order with respect to performanceEntry.startTime whose performanceEntry.name is equal to name, and optionally, whose performanceEntry.entryType is equal to type.

@since v16.7.0

abstract member getEntriesByType (type: EntryType) : PerformanceEntry array

Returns a list of PerformanceEntry objects in chronological order with respect to performanceEntry.startTime whose performanceEntry.entryType is equal to type.

@since v16.7.0

abstract member mark (name: string, ?options: MarkOptions) : PerformanceMark

Creates a new PerformanceMark entry in the Performance Timeline. A PerformanceMark is a subclass of PerformanceEntry whose performanceEntry.entryType is always 'mark', and whose performanceEntry.duration is always 0. Performance marks are used to mark specific significant moments in the Performance Timeline.

The created PerformanceMark entry is put in the global Performance Timeline and can be queried with performance.getEntries, performance.getEntriesByName, and performance.getEntriesByType. When the observation is performed, the entries should be cleared from the global Performance Timeline manually with performance.clearMarks.

abstract member markResourceTiming (timingInfo: obj, requestedUrl: string, initiatorType: string, global: obj, cacheMode: CacheMode, bodyInfo: obj, responseStatus: float, ?deliveryType: string) : PerformanceResourceTiming

Creates a new PerformanceResourceTiming entry in the Resource Timeline. A PerformanceResourceTiming is a subclass of PerformanceEntry whose performanceEntry.entryType is always 'resource'. Performance resources are used to mark moments in the Resource Timeline.

@since v18.2.0, v16.17.0

Parameter
timingInfoFetch Timing Info
requestedUrlThe resource url
initiatorTypeThe initiator name, e.g: 'fetch'
cacheModeThe cache mode must be an empty string ('') or 'local'
bodyInfoFetch Response Body Info
responseStatusThe response's status code
deliveryTypeThe delivery type. Default: ''.
abstract member measure (name: string, options: MeasureOptions) : PerformanceMeasure

Creates a new PerformanceMeasure entry in the Performance Timeline. A PerformanceMeasure is a subclass of PerformanceEntry whose performanceEntry.entryType is always 'measure', and whose performanceEntry.duration measures the number of milliseconds elapsed since startMark and endMark.

The startMark argument may identify any existing PerformanceMark in the the Performance Timeline, or may identify any of the timestamp properties provided by the PerformanceNodeTiming class. If the named startMark does not exist, then startMark is set to timeOrigin by default.

The endMark argument must identify any existing PerformanceMark in the the Performance Timeline or any of the timestamp properties provided by the PerformanceNodeTiming class. If the named endMark does not exist, an error will be thrown.

Returns. The PerformanceMeasure entry that was created

abstract member measure (name: string, ?startMark: string, ?endMark: string) : PerformanceMeasure

Creates a new PerformanceMeasure entry in the Performance Timeline. A PerformanceMeasure is a subclass of PerformanceEntry whose performanceEntry.entryType is always 'measure', and whose performanceEntry.duration measures the number of milliseconds elapsed since startMark and endMark.

The startMark argument may identify any existing PerformanceMark in the the Performance Timeline, or may identify any of the timestamp properties provided by the PerformanceNodeTiming class. If the named startMark does not exist, then startMark is set to timeOrigin by default.

The endMark argument must identify any existing PerformanceMark in the the Performance Timeline or any of the timestamp properties provided by the PerformanceNodeTiming class. If the named endMark does not exist, an error will be thrown.

Returns. The PerformanceMeasure entry that was created

abstract member now () : float

Returns the current high resolution millisecond timestamp, where 0 represents the start of the current node process.

@since v8.5.0

abstract member setResourceTimingBufferSize (maxSize: float) : unit

Sets the global performance resource timing buffer size to the specified number of "resource" type performance entry objects.

By default the max buffer size is set to 250.

@since v18.8.0

abstract member timerify<'T> (fn: 'T, ?options: TimerifyOptions) : 'T

This property is an extension by Node.js. It is not available in Web browsers.

Wraps a function within a new function that measures the running time of the wrapped function. A PerformanceObserver must be subscribed to the 'function' event type in order for the timing details to be accessed.

import {
performance,
PerformanceObserver,
} from 'node:perf_hooks';

function someFunction() {
console.log('hello world');
}

const wrapped = performance.timerify(someFunction);

const obs = new PerformanceObserver((list) => {
console.log(list.getEntries()[0].duration);

performance.clearMarks();
performance.clearMeasures();
obs.disconnect();
});
obs.observe({ entryTypes: ['function'] });

// A performance timeline entry will be created
wrapped();

If the wrapped function returns a promise, a finally handler will be attached to the promise and the duration will be reported once the finally handler is invoked.

abstract member toJSON () : obj

An object which is JSON representation of the performance object. It is similar to window.performance.toJSON in browsers.

@since v16.1.0