performance
Timestamps, marks, and measures via the Performance API, with a Date.now() fallback.
Import: @rtorcato/browser-common/performance
๐ MDN: Performance API ยท ๐ caniuse: user-timing
Browser supportโ
| API | Chrome | Edge | Firefox | Safari | iOS Safari | Baseline |
|---|---|---|---|---|---|---|
Performance.mark | โ 28+ | โ 12+ | โ 38+ | โ 11+ | โ 11+ | Widely available |
Performance.measure | โ 28+ | โ 12+ | โ 38+ | โ 11+ | โ 11+ | Widely available |
โ
supported ยท โ partial ยท โ not supported ยท [n] see note. Generated from MDN browser-compat-data and web-features. caniuse: Performance.mark ยท Performance.measure
Exampleโ
import { isPerformanceApiAvailable, now, mark, measure } from '@rtorcato/browser-common/performance'
if (isPerformanceApiAvailable()) {
mark('boot-start')
const start = now()
doWork()
mark('boot-end')
measure('boot', 'boot-start', 'boot-end')
}
Exportsโ
isPerformanceApiAvailable()โ feature checknow()โ high-resolution timestamp in ms, falls back toDate.now()getPerformanceEntriesByType(type)โ entries of a given type (e.g.'resource','mark')mark(name)โ records a named timestampmeasure(name, startMark, endMark)โ records the duration between two marks
See the API reference for full signatures.