-
-
Save gregdangelo/1560830 to your computer and use it in GitHub Desktop.
Log the time of JS operations
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
}()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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