pretty-hrtime
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|
Pretty-hrtime is a handy npm package that converts the results of the Node.js process.hrtime() function to human-readable words. The purpose of process.hrtime() function is to return the current high-resolution real time in a [seconds, nanoseconds] array, and Pretty-hrtime translates this array into a more intuitive format. This feature saves the developer's time in having to manually parse out these times for their application or system metrics.
You can easily implement pretty-hrtime by first installing it to your Node.js project through npm. After installing, you'll need to require it at the top of your file to begin using it. From there, get a starting point for your high-resolution time using the process.hrtime() method, perform the operations that you wish to measure, and then get an ending time point. Use these starting and ending time points to determine the time spent, and then feed this elapsed time into the prettyHrtime function for a human-readable result. Below is an example of how to use pretty-hrtime in your JavaScript code:
var prettyHrtime = require('pretty-hrtime');
var start = process.hrtime();
// Perform your operations here
var end = process.hrtime(start);
var words = prettyHrtime(end);
console.log(words); // Might output '1.2 ms'
words = prettyHrtime(end, {verbose:true});
console.log(words); // Might output '1 millisecond 209 microseconds'
words = prettyHrtime(end, {precise:true});
console.log(words); // Might output '1.20958 ms'
The documentation for pretty-hrtime can be found in its GitHub repository located at git://github.com/robrich/pretty-hrtime.git. It's a well-documented source providing usage examples and other additional details about integrating and using the package correctly in your projects. Whether you are new to using third-party packages or an experienced developer, the docs are straightforward and easy to understand. Do note that using pretty-hrtime requires Node.js version 0.7.6 or later, as prior versions do not support the process.hrtime() method.