Skip to content

Instantly share code, notes, and snippets.

@rocktronica
Created January 27, 2012 05:14
Show Gist options
  • Save rocktronica/1687126 to your computer and use it in GitHub Desktop.
Save rocktronica/1687126 to your computer and use it in GitHub Desktop.
JS function timer function, tinker
var rotwang = (function ($, undefined) {
this.timers = {};
this.addTime = function (sTime, iTime) {
this.timers[sTime] = this.timers[sTime] || [];
this.timers[sTime].push(iTime);
};
this.averages = (function () {
$.each(this.timers, function (key, times) {
var iTotal = 0, iCount = 0;
$.each(times, function (i, time) {
iCount++;
iTotal += time;
});
console.log(key + ' \tAverage:', Math.round(iTotal / iCount), ' \tTotal:', iTotal, ' \t Items:', iCount, times);
});
});
return this;
} (jQuery));
@rocktronica
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment