node-tictoc
Advanced tools
Comparing version 1.0.0 to 1.1.0
40
index.js
@@ -1,4 +0,10 @@ | ||
// Stack of timers | ||
/** | ||
* Stack of timers | ||
* @type {Array} | ||
*/ | ||
var timers = []; | ||
/** | ||
* Creates a new timer | ||
*/ | ||
module.exports.tic = function () { | ||
@@ -8,16 +14,30 @@ timers.push(process.hrtime()); | ||
/** | ||
* Prints the elapsed seconds and milliseconds for the most recent timer | ||
*/ | ||
module.exports.toc = function () { | ||
if (! timers.length) return; | ||
var time = this.toct(); | ||
var time = process.hrtime(timers.pop()), | ||
seconds = time[0], | ||
nanos = time[1], | ||
ms = nanos / 1000000; | ||
var result = ''; | ||
if (seconds) result += seconds + ' seconds '; | ||
if (ms) result += ms + ' ms '; | ||
if (time.seconds) result += time.seconds + ' seconds '; | ||
if (time.ms) result += time.ms + ' ms '; | ||
console.log(result); | ||
}; | ||
}; | ||
/** | ||
* If you just want the elapsed time without printing | ||
* @return {Object} Contains the time conversions (seconds, nanos, ms) for the most recent timer | ||
*/ | ||
module.exports.toct = function() { | ||
if (! timers.length) return null; | ||
var time = process.hrtime(timers.pop()); | ||
return { | ||
seconds: time[0], | ||
nanos: time[1], | ||
ms: time[1] / 1000000 | ||
}; | ||
}; |
{ | ||
"name": "node-tictoc", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "Simple stopwatch timer for profiling operations", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -1,7 +0,9 @@ | ||
node-tictoc | ||
=== | ||
### tictoc | ||
Wrapper around `process.hrtime` that lets you have a stack of | ||
timers with a simpler api and more useful output: | ||
`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 | ||
```javascript | ||
@@ -31,2 +33,14 @@ var time = require('node-tictoc'); | ||
} | ||
``` | ||
``` | ||
If you just want the time values: | ||
```javascript | ||
time.toct() | ||
``` | ||
Returns an object with the following values for the most recent timer (started with `tic`): | ||
* `seconds` | ||
* `nanos` | ||
* `ms` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2817
57
46