Skip to content

Instantly share code, notes, and snippets.

@gregdangelo
Forked from ryanflorence/logtime.js
Created January 4, 2012 16:33
Show Gist options
  • Save gregdangelo/1560830 to your computer and use it in GitHub Desktop.
Save gregdangelo/1560830 to your computer and use it in GitHub Desktop.
Log the time of JS operations
var logtime = (function() {
var ids = {};
return function(id) {
if (!ids[id]) {
ids[id] = +new Date();
return;
}
var time = +new Date() - ids[id];
delete ids[id];
console.log(id + ': ' + time + 'ms');
return time;
}
}());
logtime('foo');
doSomethingExpensive();
logtime('foo'); // console logs the time between calls to logtime('foo')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment