performance-now
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|
Performance-now is a JavaScript module that implements a function similar to performance.now
, based on Node.js native process.hrtime
function. Essentially, it allows measuring time with sub-millisecond precision in Node applications. Unlike the standard clock time, the time reported by performance-now is monotonically increasing, keeping it safe from clock-drift issues.
To use performance-now, you will need to install it via npm and then use require to include it in your project. Here is an example on how to use it in your JavaScript code:
// Install the module first with npm install performance-now
// Then, in your JavaScript code, require the module
var now = require("performance-now");
// You can then use it to measure the time
var start = now();
// Execute your code here
var end = now();
// You can then calculate the time difference
console.log((end - start).toFixed(3)); // Time in milliseconds taken by your code
This couldn't be simpler: just call the now()
function before and after the code you want to measure the time of. The numbers returned by now()
are in milliseconds with sub-millisecond precision.
The documentation for performance-now is relatively limited and is primarily found in the README.md file available in the GitHub repository, at git://github.com/braveg1rl/performance-now.git. The repository provides crucial details about its installation and usage including a basic code example. For more detailed usage, the module mirrors the interface of the standard performance.now
method you can find in modern web browsers, therefore existing standard documentation for this method is also applicable to performance-now.