node-tictoc

1.3.0 • Public • Published

tictoc

npm install node-tictoc

Wrapper around process.hrtime that lets you have a stack of timers with a simpler api and more useful output:

Usage

  var time = require('node-tictoc');
 
  time.tic();
 
  for(var i = 0; i < 1000; i++) {
    // do something
  }
 
  time.toc(); // prints the elapsed seconds and/or milliseconds

Or a recursive timing solution that takes advantage of the stack:

  function foo(n) {
    if (! n) return;
 
    time.tic();
 
    foo(- 1);
 
    time.toc(); // prints the elapsed time in last-in-first-out (LIFO) order
  }

If you just want the time values:

  time.toct()

If you want the profiling string but don't want it console logged automatically:

  time.stoc();

Returns an object with the following values for the most recent timer (started with tic):

  • seconds
  • nanos
  • ms

Package Sidebar

Install

npm i node-tictoc

Weekly Downloads

3

Version

1.3.0

License

MIT

Last publish

Collaborators

  • mrjoelkemp