What is browser-process-hrtime?
The browser-process-hrtime package is a browser shim for Node.js's process.hrtime. It allows you to get high-resolution real-time stamps with nanosecond precision, which is useful for performance testing, benchmarking, or tracking the time between events with high accuracy.
What are browser-process-hrtime's main functionalities?
High-resolution time stamps
This feature allows you to measure precise time intervals. The code sample demonstrates how to get the current high-resolution real-time stamp, wait for 1 second using setTimeout, and then get another time stamp to calculate the duration.
const now = require('browser-process-hrtime');
const start = now();
setTimeout(function () {
const end = now(start);
console.log('seconds:', end[0]);
console.log('nanoseconds:', end[1]);
}, 1000);
Other packages similar to browser-process-hrtime
performance-now
This package provides a function that returns the current timestamp in milliseconds. It's similar to browser-process-hrtime but does not provide nanosecond precision.
hrtime
hrtime is another shim for process.hrtime. It offers similar functionality to browser-process-hrtime, providing high-resolution real-time stamps.
nano-time
nano-time gives you the current time in nanoseconds as a string. It's similar to browser-process-hrtime in that it provides high precision timing, but it does not use the same API as process.hrtime.
browser-process-hrtime
Browser shim for Node.js process.hrtime().
See documentation at nodejs.org
usage
You can monkey-patch process.hrtime for your dependency graph like this
process.hrtime = require('browser-process-hrtime')
var coolTool = require('module-that-uses-hrtime-somewhere-in-its-depths')
note
This was originally pull-requested against node-process,
but they are trying to stay lean.