Comparing version 3.1.0 to 3.2.0
@@ -28,13 +28,18 @@ (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.unitimer = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ | ||
var startTime = null | ||
var startTimes = {} | ||
return { | ||
start: function () { | ||
start: function (id) { | ||
var time = now() | ||
startTime = time | ||
if (id) { | ||
startTimes[id] = time | ||
} else { | ||
startTime = time | ||
} | ||
return this | ||
}, | ||
stop: function () { | ||
if (!startTime) { return -1 } | ||
var stopTime = now() | ||
var took = stopTime - startTime | ||
stop: function (id) { | ||
const t = id ? startTimes[id] : startTime | ||
if (!t) { return -1 } | ||
var took = now() - t | ||
minTime = minTime === -1 ? took : Math.min(minTime, took) | ||
@@ -45,3 +50,7 @@ maxTime = maxTime === -1 ? took : Math.max(maxTime, took) | ||
meanTime = totalTime / count | ||
startTime = null | ||
if (id) { | ||
startTimes[id] = undefined | ||
} else { | ||
startTime = null | ||
} | ||
return took | ||
@@ -48,0 +57,0 @@ }, |
@@ -17,13 +17,18 @@ var now = require('./now') | ||
var startTime = null | ||
var startTimes = {} | ||
return { | ||
start: function () { | ||
start: function (id) { | ||
var time = now() | ||
startTime = time | ||
if (id) { | ||
startTimes[id] = time | ||
} else { | ||
startTime = time | ||
} | ||
return this | ||
}, | ||
stop: function () { | ||
if (!startTime) { return -1 } | ||
var stopTime = now() | ||
var took = stopTime - startTime | ||
stop: function (id) { | ||
const t = id ? startTimes[id] : startTime | ||
if (!t) { return -1 } | ||
var took = now() - t | ||
minTime = minTime === -1 ? took : Math.min(minTime, took) | ||
@@ -34,3 +39,7 @@ maxTime = maxTime === -1 ? took : Math.max(maxTime, took) | ||
meanTime = totalTime / count | ||
startTime = null | ||
if (id) { | ||
startTimes[id] = undefined | ||
} else { | ||
startTime = null | ||
} | ||
return took | ||
@@ -37,0 +46,0 @@ }, |
{ | ||
"name": "unitimer", | ||
"version": "3.1.0", | ||
"version": "3.2.0", | ||
"description": "Universal timer (Node.js and browser)", | ||
@@ -49,9 +49,9 @@ "main": "./lib/index.js", | ||
"devDependencies": { | ||
"ava": "^0.16.0", | ||
"browserify": "^13.1.0", | ||
"ava": "0.19.1", | ||
"browserify": "14.3.0", | ||
"proxyquire": "^1.7.10", | ||
"sinon": "^1.17.5", | ||
"standard": "^8.0.0", | ||
"sinon": "2.2.0", | ||
"standard": "10.0.2", | ||
"watchify": "^3.7.0" | ||
} | ||
} |
@@ -61,8 +61,8 @@ # unitimer | ||
### `timer.info()` | ||
### `timer.info(precision)` | ||
Returns a string summary of timer total, mean, total, min and max. | ||
Returns a string summary of timer total, mean, total, min and max. `precision` is number of decimal places to show (_optional_). | ||
### `timer.log()` | ||
### `timer.log(precision)` | ||
`console.log` of `timer.info()` (see above) |
@@ -10,3 +10,3 @@ const test = require('ava') | ||
} | ||
return sinon.stub(process, 'hrtime', fn) | ||
return sinon.stub(process, 'hrtime').callsFake(fn) | ||
} | ||
@@ -31,2 +31,20 @@ | ||
test('handles async start() then stop() using optional identifier', (t) => { | ||
const times = [ | ||
[4, 0], | ||
[4, 0], | ||
[9, 0], | ||
[10, 0] | ||
] | ||
const hrtime = stubHrtime(times) | ||
const timer = createTimer() | ||
timer.start('a') | ||
timer.start('b') | ||
const msA = timer.stop('a') | ||
const msB = timer.stop('b') | ||
t.is(msA, 5000) | ||
t.is(msB, 6000) | ||
hrtime.restore() | ||
}) | ||
test('stop() with no start() returns -1', (t) => { | ||
@@ -33,0 +51,0 @@ const timer = createTimer() |
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
162688
12
480