New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

time-diff

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

time-diff

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

  • 0.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
26K
decreased by-3.71%
Maintainers
1
Weekly downloads
 
Created
Source

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.

Keywords

FAQs

Package last updated on 20 Dec 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc