Comparing version 3.0.0 to 3.1.0
@@ -14,2 +14,9 @@ (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){ | ||
function toFixed (v, dp) { | ||
if (typeof dp === 'undefined') { | ||
return v | ||
} | ||
return v.toFixed(dp) | ||
} | ||
function createInstance (tag) { | ||
@@ -65,13 +72,13 @@ var totalTime = 0 | ||
}, | ||
info: function () { | ||
info: function (dp) { | ||
return (tag ? '[' + tag + '] ' : '') + | ||
'mean: ' + meanTime + | ||
'ms, total: ' + totalTime + | ||
'mean: ' + toFixed(meanTime, dp) + | ||
'ms, total: ' + toFixed(totalTime, dp) + | ||
'ms, count: ' + count + | ||
', min: ' + minTime + | ||
'ms, max: ' + maxTime + | ||
', min: ' + toFixed(minTime, dp) + | ||
'ms, max: ' + toFixed(maxTime, dp) + | ||
'ms' | ||
}, | ||
log: function () { | ||
console.log(this.info()) | ||
log: function (dp) { | ||
console.log(this.info(dp)) | ||
} | ||
@@ -78,0 +85,0 @@ } |
@@ -1,1 +0,1 @@ | ||
!function(f){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=f();else if("function"==typeof define&&define.amd)define([],f);else{var g;g="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,g.unitimer=f()}}(function(){return function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a="function"==typeof require&&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}for(var i="function"==typeof require&&require,o=0;o<r.length;o++)s(r[o]);return s}({1:[function(require,module,exports){function now(){return"undefined"!=typeof window.performance&&"undefined"!=typeof window.performance.now?window.performance.now():Date.now()}module.exports=now},{}],2:[function(require,module,exports){function createInstance(tag){var totalTime=0,meanTime=0,minTime=-1,maxTime=-1,count=0,startTime=null;return{start:function(){var time=now();return startTime=time,this},stop:function(){if(!startTime)return-1;var stopTime=now(),took=stopTime-startTime;return minTime=minTime===-1?took:Math.min(minTime,took),maxTime=maxTime===-1?took:Math.max(maxTime,took),totalTime+=took,count+=1,meanTime=totalTime/count,startTime=null,took},total:function(){return totalTime},mean:function(){return meanTime},count:function(){return count},min:function(){return minTime},max:function(){return maxTime},stats:function(){return{total:totalTime,mean:meanTime,count:count,min:minTime,max:maxTime}},info:function(){return(tag?"["+tag+"] ":"")+"mean: "+meanTime+"ms, total: "+totalTime+"ms, count: "+count+", min: "+minTime+"ms, max: "+maxTime+"ms"},log:function(){console.log(this.info())}}}function isArray(o){return"[object Array]"===Object.prototype.toString.call(o)}function isString(o){return"string"==typeof o||o instanceof String}function createTimer(tags){if(isArray(tags)){for(var a=[],i=0;i<tags.length;i+=1)a.push(createInstance(tags[i]));return a}return isString(tags)?createInstance(tags):createInstance()}var now=require("./now");module.exports=createTimer},{"./now":1}]},{},[2])(2)}); | ||
!function(f){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=f();else if("function"==typeof define&&define.amd)define([],f);else{var g;g="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,g.unitimer=f()}}(function(){return function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a="function"==typeof require&&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}for(var i="function"==typeof require&&require,o=0;o<r.length;o++)s(r[o]);return s}({1:[function(require,module,exports){function now(){return"undefined"!=typeof window.performance&&"undefined"!=typeof window.performance.now?window.performance.now():Date.now()}module.exports=now},{}],2:[function(require,module,exports){function toFixed(v,dp){return"undefined"==typeof dp?v:v.toFixed(dp)}function createInstance(tag){var totalTime=0,meanTime=0,minTime=-1,maxTime=-1,count=0,startTime=null;return{start:function(){var time=now();return startTime=time,this},stop:function(){if(!startTime)return-1;var stopTime=now(),took=stopTime-startTime;return minTime=minTime===-1?took:Math.min(minTime,took),maxTime=maxTime===-1?took:Math.max(maxTime,took),totalTime+=took,count+=1,meanTime=totalTime/count,startTime=null,took},total:function(){return totalTime},mean:function(){return meanTime},count:function(){return count},min:function(){return minTime},max:function(){return maxTime},stats:function(){return{total:totalTime,mean:meanTime,count:count,min:minTime,max:maxTime}},info:function(dp){return(tag?"["+tag+"] ":"")+"mean: "+toFixed(meanTime,dp)+"ms, total: "+toFixed(totalTime,dp)+"ms, count: "+count+", min: "+toFixed(minTime,dp)+"ms, max: "+toFixed(maxTime,dp)+"ms"},log:function(dp){console.log(this.info(dp))}}}function isArray(o){return"[object Array]"===Object.prototype.toString.call(o)}function isString(o){return"string"==typeof o||o instanceof String}function createTimer(tags){if(isArray(tags)){for(var a=[],i=0;i<tags.length;i+=1)a.push(createInstance(tags[i]));return a}return isString(tags)?createInstance(tags):createInstance()}var now=require("./now");module.exports=createTimer},{"./now":1}]},{},[2])(2)}); |
var now = require('./now') | ||
function toFixed (v, dp) { | ||
if (typeof dp === 'undefined') { | ||
return v | ||
} | ||
return v.toFixed(dp) | ||
} | ||
function createInstance (tag) { | ||
@@ -53,13 +60,13 @@ var totalTime = 0 | ||
}, | ||
info: function () { | ||
info: function (dp) { | ||
return (tag ? '[' + tag + '] ' : '') + | ||
'mean: ' + meanTime + | ||
'ms, total: ' + totalTime + | ||
'mean: ' + toFixed(meanTime, dp) + | ||
'ms, total: ' + toFixed(totalTime, dp) + | ||
'ms, count: ' + count + | ||
', min: ' + minTime + | ||
'ms, max: ' + maxTime + | ||
', min: ' + toFixed(minTime, dp) + | ||
'ms, max: ' + toFixed(maxTime, dp) + | ||
'ms' | ||
}, | ||
log: function () { | ||
console.log(this.info()) | ||
log: function (dp) { | ||
console.log(this.info(dp)) | ||
} | ||
@@ -66,0 +73,0 @@ } |
{ | ||
"name": "unitimer", | ||
"version": "3.0.0", | ||
"version": "3.1.0", | ||
"description": "Universal timer (Node.js and browser)", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index.js", |
@@ -181,6 +181,6 @@ const test = require('ava') | ||
const times = [ | ||
[5, 0], | ||
[10, 0], | ||
[20, 0], | ||
[30, 0] | ||
[5, 99], | ||
[10, 10000], | ||
[20, 3], | ||
[30, 50000] | ||
] | ||
@@ -194,4 +194,8 @@ const hrtime = stubHrtime(times) | ||
timer.info(), | ||
'mean: 7500ms, total: 15000ms, count: 2, min: 5000ms, max: 10000ms' | ||
'mean: 7500.029949ms, total: 15000.059898ms, count: 2, min: 5000.009901ms, max: 10000.049996999998ms' | ||
) | ||
t.is( | ||
timer.info(3), | ||
'mean: 7500.030ms, total: 15000.060ms, count: 2, min: 5000.010ms, max: 10000.050ms' | ||
) | ||
t.is(typeof timer.log, 'function') | ||
@@ -198,0 +202,0 @@ hrtime.restore() |
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
17396
445