package
Precision timer for nanosecond differences
npm install preciseGitHub-flavored package documentation.
Across all versions.
Download trend unavailable.
Runtime metadata.
Tagged topics.
Estimated unpacked size across 1 packages.
15.1 kB
Includes dependencies.
Nanosecond-precision timer for Node.js using process.hrtime.bigint().
performance.now()?While performance.now() provides millisecond precision with sub-millisecond fractional parts, precise delivers true nanosecond accuracy using Node.js's process.hrtime.bigint() API:
| Method | Precision | Resolution |
|---|---|---|
performance.now() | Milliseconds | ~0.1-1ms |
precise | Nanoseconds | ~1ns |
For performance-critical applications measuring code execution, benchmarking, or profiling, the 6 decimal places of additional precision can reveal timing differences that performance.now() simply cannot detect.
import {precise} from "precise";
const timer = precise().start();
setTimeout(() => console.log(timer.stop().diff()), 1000);import {Precise} from "precise";
const timer = new Precise().start();
setTimeout(() => console.log(timer.stop().diff()), 1000);import {Precise} from "precise";
class MyTimer extends Precise {}Precise has 100% code coverage with its tests.
ℹ start of coverage report
ℹ ----------------------------------------------------------
ℹ file | line % | branch % | funcs % | uncovered lines
ℹ ----------------------------------------------------------
ℹ ----------------------------------------------------------
ℹ all files | 100.00 | 100.00 | 100.00 |
ℹ ----------------------------------------------------------
ℹ end of coverage reportReturns the time delta between start() & stop(); setting optional parameter to true will return the delta as milliseconds
Returns the elapsed time since start() without stopping the timer
Returns a human-readable string of the elapsed time. Optional delta parameter allows formatting a custom nanosecond value.
Reset a timer
Starts a timer
Stops a timer
Copyright (c) 2026 Jason Mulligan Licensed under the BSD-3 license