
Security News
Browserslist-rs Gets Major Refactor, Cutting Binary Size by Over 1MB
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
Returns the formatted, high-resolution time difference between `start` and `end` times.
Returns the formatted, high-resolution time difference between
start
andend
times.
Install with npm:
$ npm install time-diff --save
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
Start a timer for the given name
.
Params
name
{String}: Name to use for the starting time.returns
{Array}: Returns the array from process.hrtime()
Example
var time = new Time();
time.start('foo');
Returns the cumulative elapsed time since the first time time.start(name)
was called.
Params
name
{String}: The name of the cached starting time to create the diffreturns
{Array}: Returns the array from process.hrtime()
Example
var time = new Time();
time.start('foo');
// do stuff
time.end('foo');
//=> 104μs
// do more stuff
time.end('foo');
//=> 1ms
// do more stuff
time.end('foo');
//=> 2ms
Returns a function for logging out out both the cumulative elapsed time since the first time .diff(name)
was called, as well as the incremental elapsed time since the last .diff(name)
was called. Unlike .end()
, this method logs to stderr
instead of returning a string. We could probably change this to return an object, feedback welcome.
Results in something like:
Params
name
{String}: The name of the starting time to store.options
{String}Example
var time = new Time();
var diff = time.diff('my-app-name');
// do stuff
diff('after init');
//=> [19:44:05] my-app-name: after init 108μs
// do more stuff
diff('before options');
//=> [19:44:05] my-app-name: before options 2ms (+2ms)
// do more stuff
diff('after options');
//=> [19:44:05] my-app-name: after options 2ms (+152μs)
Create an instance of Time
, optionally specifying the time scale to use and the number of decimal places to display.
Options
options.smallest
: the smallest time scale to showoptions.digits
: the number of decimal places to display (digits
)Examples
(See pretty-time for all available formats)
Given the following:
var time = new Time(options);
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
You might also be interested in these projects:
process.hrtime
. Works with timescales ranging from weeks to nanoseconds. | homepagestart
and end
times. | homepagePull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Generate readme and API documentation with verb:
$ npm install verb && npm run docs
Or, if verb is installed globally:
$ verb
Install dev dependencies:
$ npm install -d && npm test
Jon Schlinkert
Copyright © 2016, Jon Schlinkert. Released under the MIT license.
This file was generated by verb, v0.9.0, on April 13, 2016.
FAQs
Returns the formatted, high-resolution time difference between `start` and `end` times.
The npm package time-diff receives a total of 29,108 weekly downloads. As such, time-diff popularity was classified as popular.
We found that time-diff demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
Research
Security News
Eight new malicious Firefox extensions impersonate games, steal OAuth tokens, hijack sessions, and exploit browser permissions to spy on users.
Security News
The official Go SDK for the Model Context Protocol is in development, with a stable, production-ready release expected by August 2025.