Timestamp getter wrapping (in order of preference) `process.hrtime.bigint()`, `performance.now()` or `Date.now()`
npm install @thi.ng/timestamp
!npm downloads

> [!NOTE]
> This is one of 214 standalone projects, maintained as part
> of the @thi.ng/umbrella monorepo
> and anti-framework.
>
> 🚀 Please help me to work full-time on these projects by sponsoring me on
> GitHub. Thank you! ❤️
- About
- Status
- Installation
- Dependencies
- API
- Authors
- License
Timestamp getter wrapping (in order of preference) process.hrtime.bigint(), performance.now() or Date.now().
> [!NOTE]
> The functions in this package have been extracted from
> @thi.ng/bench.
This package provides the following functions:
- now() attempts
to use high-res ESBigInt
timestamps (in Node viaprocess.hrtime.bigint()),
or falls back to performance.now(), or lacking that, uses Date.now(). In all
cases, returns a (possibly rounded) nanosec-scale timestamp, either as bigint
or number.
- timeDiff()
function can be used to compute the difference between two such timestamp and
return it as milliseconds.
- asMillis()
takes a duration (either a number or bigint) in nanosec-scale and converts it
to a JS number in milliseconds
STABLE - used in production
Search or submit any issues for this package
``bash`
yarn add @thi.ng/timestamp
ESM import:
`ts`
import * as tim from "@thi.ng/timestamp";
Browser ESM import:
`html`
For Node.js REPL:
`js`
const tim = await import("@thi.ng/timestamp");
Package sizes (brotli'd, pre-treeshake): ESM: 213 bytes
None
TODO
If this project contributes to an academic publication, please cite it as:
`bibtex``
@misc{thing-timestamp,
title = "@thi.ng/timestamp",
author = "Karsten Schmidt",
note = "https://thi.ng/timestamp",
year = 2018
}
© 2018 - 2026 Karsten Schmidt // Apache License 2.0