Socket
Socket
Sign inDemoInstall

unitimer

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

unitimer - npm Package Compare versions

Comparing version 2.0.0 to 2.1.0

30

dist/unitimer.js

@@ -14,3 +14,3 @@ (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 unitimer () {
function createInstance (tag) {
var totalTime = 0

@@ -66,7 +66,8 @@ var meanTime = 0

info: function () {
return 'mean: ' + meanTime +
'ms, total: ' + totalTime +
'ms, count: ' + count +
', min: ' + minTime +
'ms, max: ' + maxTime +
return (tag ? tag + ': ' : '') +
'mean=' + meanTime +
'ms, total=' + totalTime +
'ms, count=' + count +
', min=' + minTime +
'ms, max=' + maxTime +
'ms'

@@ -80,5 +81,20 @@ },

module.exports = unitimer
function createTimer () {
var tags = Array.prototype.slice.call(arguments)
// Named instances
if (tags.length > 0) {
var r = {}
tags.forEach(function (tag) {
r[tag] = createInstance(tag)
})
return r
}
return createInstance()
}
module.exports = createTimer
},{"./now":1}]},{},[2])(2)
});

@@ -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 unitimer(){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"mean: "+meanTime+"ms, total: "+totalTime+"ms, count: "+count+", min: "+minTime+"ms, max: "+maxTime+"ms"},log:function(){console.log(this.info())}}}var now=require("./now");module.exports=unitimer},{"./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 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 createTimer(){var tags=Array.prototype.slice.call(arguments);if(tags.length>0){var r={};return tags.forEach(function(tag){r[tag]=createInstance(tag)}),r}return createInstance()}var now=require("./now");module.exports=createTimer},{"./now":1}]},{},[2])(2)});
var now = require('./now')
function unitimer () {
function createInstance (tag) {
var totalTime = 0

@@ -54,7 +54,8 @@ var meanTime = 0

info: function () {
return 'mean: ' + meanTime +
'ms, total: ' + totalTime +
'ms, count: ' + count +
', min: ' + minTime +
'ms, max: ' + maxTime +
return (tag ? tag + ': ' : '') +
'mean=' + meanTime +
'ms, total=' + totalTime +
'ms, count=' + count +
', min=' + minTime +
'ms, max=' + maxTime +
'ms'

@@ -68,2 +69,17 @@ },

module.exports = unitimer
function createTimer () {
var tags = Array.prototype.slice.call(arguments)
// Named instances
if (tags.length > 0) {
var r = {}
tags.forEach(function (tag) {
r[tag] = createInstance(tag)
})
return r
}
return createInstance()
}
module.exports = createTimer
{
"name": "unitimer",
"version": "2.0.0",
"version": "2.1.0",
"description": "Universal timer (Node.js and browser)",

@@ -5,0 +5,0 @@ "main": "./lib/index.js",

@@ -191,5 +191,5 @@ const test = require('ava')

timer.stop()
t.deepEqual(
t.is(
timer.info(),
'mean: 7500ms, total: 15000ms, count: 2, min: 5000ms, max: 10000ms'
'mean=7500ms, total=15000ms, count=2, min=5000ms, max=10000ms'
)

@@ -199,1 +199,49 @@ t.is(typeof timer.log, 'function')

})
test('create single with tags', (t) => {
const times = [
[5, 0],
[10, 0],
[20, 0],
[30, 0]
]
const hrtime = stubHrtime(times)
const { foo, bar } = createTimer('foo', 'bar')
foo.start()
foo.stop()
bar.start()
bar.stop()
t.is(
foo.info(),
'foo: mean=5000ms, total=5000ms, count=1, min=5000ms, max=5000ms'
)
t.is(
bar.info(),
'bar: mean=10000ms, total=10000ms, count=1, min=10000ms, max=10000ms'
)
hrtime.restore()
})
test('create multiple with tags', (t) => {
const times = [
[5, 0],
[10, 0],
[20, 0],
[30, 0]
]
const hrtime = stubHrtime(times)
const { foo, bar } = createTimer('foo', 'bar')
foo.start()
foo.stop()
bar.start()
bar.stop()
t.is(
foo.info(),
'foo: mean=5000ms, total=5000ms, count=1, min=5000ms, max=5000ms'
)
t.is(
bar.info(),
'bar: mean=10000ms, total=10000ms, count=1, min=10000ms, max=10000ms'
)
hrtime.restore()
})
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc