Skip to main content

Module performance

Module performance 

Source
Expand description

performance: High Resolution Time, User Timing and the Performance Timeline.

now() reads a monotonic Instant, never the wall clock. That is the whole point of the API — a Date.now() delta can go backwards when NTP steps the clock mid-measurement, and a timing number that silently goes backwards is worse than no timing number. The wall clock appears exactly once, as timeOrigin, which is what the monotonic readings are relative to.

monotonic_base is also what process.hrtime counts from, so the two clocks are correlatable the way Node’s are (both derive from one libuv hrtime there).

Covered: now, timeOrigin, toJSON, mark, measure, clearMarks, clearMeasures, getEntries, getEntriesByName, getEntriesByType, and the PerformanceEntry / PerformanceMark / PerformanceMeasure classes with PerformanceEntry as their prototype, so mark instanceof PerformanceEntry holds.

Not covered: PerformanceObserver (it needs a task-queue hook this runtime has no equivalent of), the resource/navigation timing entry types (no document), and Node’s eventLoopUtilization / nodeTiming. A buffer size limit is not implemented either; nothing here evicts, so a program marking in a hot loop grows the buffer until it calls clearMarks, exactly as the spec’s maxBufferSize exists to bound.

Structs§

PerformanceEntryJs
PerformanceEntry — the base every timeline entry reads as.
PerformanceJs
performance.
PerformanceMarkJs
PerformanceMark — a PerformanceEntry plus the detail its creator attached.
PerformanceMeasureJs
PerformanceMeasure — an interval between two points on the timeline.

Functions§

init
Define the four classes and install the performance instance.
monotonic_base
The process-wide monotonic origin. process.hrtime counts from this too, so a script can line its readings up against performance.now().
now_ms
performance.now() in fractional milliseconds.
time_origin_ms
performance.timeOrigin: Unix-epoch milliseconds at the monotonic base.