Skip to content

iexitdev/hr-time-modern

hr-time-modern

Modern high-resolution timing helpers for JavaScript and TypeScript.

w3c-hr-time is deprecated because current platforms expose performance.now() and performance.timeOrigin natively. This package keeps the small compatibility surface that old code used while delegating to native timing APIs.

Install

npm install hr-time-modern

Usage

import { Performance, getGlobalMonotonicClockMS } from "hr-time-modern";

const performance = new Performance();

setTimeout(() => {
  console.log(performance.now());
}, 100);

console.log(getGlobalMonotonicClockMS());

API

new Performance()

Creates an isolated timer with:

  • timeOrigin: high-resolution Unix timestamp for construction time.
  • now(): milliseconds elapsed since construction.
  • toJSON(): { timeOrigin }.

getGlobalMonotonicClockMS()

Returns a monotonically increasing millisecond timestamp.

clockIsAccurate

Always true on supported runtimes.

nativePerformance

The platform performance object used internally.

Migration Position

hr-time-modern is an independent alternative or migration helper for projects moving away from w3c-hr-time. It is not affiliated with the original package maintainers or project.

For release context, see the local migration guide, examples, compatibility notes, source metadata, and adoption plan.

About

Modern high-resolution timing helpers and w3c-hr-time compatibility exports.

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors