time-diff
![Build Status](https://img.shields.io/travis/jonschlinkert/time-diff.svg)
Returns the formatted, high-resolution time difference between start
and end
times.
(TOC generated by verb)
Install
Install with npm
$ npm i time-diff --save
Usage
Uses pretty-time to format time diffs.
var Time = require('time-diff');
var time = new Time();
time.start('foo');
console.log(time.end('foo'));
API
Create an instance of Time
, optionally specifying the time scale to use and the number of decimal places to display.
Params
smallest
: the smallest time scale to showdigits
: the number of decimal places to display (digits
)
Examples
(See pretty-time for all available formats)
Given the following:
var time = new Time();
time.start('foo');
Returns milliseconds by default
console.log(time.end('foo'));
Milliseconds to 3 decimal places
console.log(time.end('foo', 'ms', 3));
console.log(time.end('foo', 3));
Seconds to 3 decimal places
console.log(time.end('foo', 's', 3));
Seconds
console.log(time.end('foo', 's'));
Microseconds
console.log(time.end('foo', 'μs'));
Microseconds to 2 decimal places
console.log(time.end('foo', 'μs', 2));
nano-seconds
console.log(time.end('foo', 'n', 3));
nano-seconds to 3 decimal places
console.log(time.end('foo', 'n', 3));
Related projects
pretty-time: Easily format the time from node.js process.hrtime
. Works with timescales ranging from weeks to nanoseconds. | homepage
Running tests
Install dev dependencies:
$ npm i -d && npm test
Contributing
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Author
Jon Schlinkert
License
Copyright © 2015 Jon Schlinkert
Released under the MIT license.
This file was generated by verb on December 20, 2015.