Skip to main content

@rtorcato/browser-common / performance

performance

Functions

isPerformanceApiAvailable()

isPerformanceApiAvailable(): boolean

Defined in: performance/index.ts:9

Checks if the Performance API is available in the current environment.

Example

import { isPerformanceApiAvailable } from '@rtorcato/browser-common/performance'
if (isPerformanceApiAvailable()) trace()

Returns

boolean


now()

now(): number

Defined in: performance/index.ts:23

Returns the current high-resolution timestamp (in milliseconds). Falls back to Date.now() if not available.

Example

import { now } from '@rtorcato/browser-common/performance'
const start = now()
const elapsed = now() - start

Returns

number


getPerformanceEntriesByType()

getPerformanceEntriesByType(type): PerformanceEntry[]

Defined in: performance/index.ts:40

Gets all performance entries of a given type (e.g., 'resource', 'mark', 'measure').

Example

import { getPerformanceEntriesByType } from '@rtorcato/browser-common/performance'
const resources = getPerformanceEntriesByType('resource')

Parameters

type

string

The entry type.

Returns

PerformanceEntry[]

An array of PerformanceEntry objects, or an empty array if not supported.


mark()

mark(name): void

Defined in: performance/index.ts:56

Marks a named timestamp in the performance timeline.

Example

import { mark } from '@rtorcato/browser-common/performance'
mark('boot-start')

Parameters

name

string

The mark name.

Returns

void


measure()

measure(name, startMark, endMark): void

Defined in: performance/index.ts:74

Measures the time between two marks.

Example

import { mark, measure } from '@rtorcato/browser-common/performance'
mark('start'); doWork(); mark('end')
measure('work', 'start', 'end')

Parameters

name

string

The measure name.

startMark

string

The starting mark name.

endMark

string

The ending mark name.

Returns

void