@zendesk/react-measure-timing-hooks
Version:
react hooks for measuring time to interactive and time to render of components
30 lines (29 loc) • 1.47 kB
TypeScript
import type { Timestamp } from './types';
/**
* Ensures that the input timestamp object has both epoch and performance.now() time.
* If no input is provided, it generates a new timestamp with the current time.
*
* why store both timestamps?:
* - epoch time: for reporting absolute time / correlating with backends
* - durations: for calculating durations between two timestamps, performance.now() time makes more sense
* - both are needed to correctly calculate a drift-adjusted epoch time
*
* @param input - Partial timestamp object that may contain either epoch or now or both.
* @returns Full timestamp object with both epoch and performance.now() time.
*/
export declare const ensureTimestamp: (input?: Partial<Timestamp>) => Timestamp;
/**
* Why do we need to account for drift?
* - monotonic clock (performance.now()) is not guaranteed to be in sync with wall clock time (Date.now())
* - Earth’s rotation speed is not constant
* - browser bugs cause the monotonic clock to not tick when the computer is asleep or when the process is throttled
* @see
* - https://github.com/w3c/performance-timeline/issues/206
* - https://dev.to/noamr/when-a-millisecond-is-not-a-millisecond-3h6
* - https://issues.chromium.org/issues/41450546
*/
export declare function getEpochCorrectedForDrift({ epoch, now }: Timestamp): number;
export declare const adjustTimestampBy: (timestamp: Timestamp, adjustment: number) => {
epoch: number;
now: number;
};