JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 33491
  • Score
    100M100P100Q144987F
  • License MIT

Returns the formatted, high-resolution time difference between `start` and `end` times.

Package Exports

  • time-diff

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (time-diff) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

time-diff NPM version Build Status

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();

// create a start time for `foo`
time.start('foo');

// call `end` wherever the `foo` process ends
console.log(time.end('foo'));
//=> 12ms

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 show
  • digits: 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'));
//=> 13ms

Milliseconds to 3 decimal places

console.log(time.end('foo', 'ms', 3));
// or
console.log(time.end('foo', 3));
//=> 12.743ms

Seconds to 3 decimal places

console.log(time.end('foo', 's', 3));
//=> 0.013s

Seconds

console.log(time.end('foo', 's'));
//=> 0s

Microseconds

console.log(time.end('foo', 'μs'));
//=> 12ms 934μs

Microseconds to 2 decimal places

console.log(time.end('foo', 'μs', 2));
//=> 14ms 435.78μs

nano-seconds

console.log(time.end('foo', 'n', 3));
//=> 13ms 796μs 677ns

nano-seconds to 3 decimal places

console.log(time.end('foo', 'n', 3));
//=> 13ms 427μs 633.000ns

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.