Last active
December 10, 2015 02:38
-
-
Save jamestomasino/4369616 to your computer and use it in GitHub Desktop.
Get the time elapsed since the last call to the checkInterval function. Useful for quick profiling tasks.
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
function interval () { | |
var lastTime = new Date().getTime() / 1000; | |
return function getInterval () { | |
var newTime = new Date().getTime() / 1000; | |
var delta = newTime - lastTime; | |
lastTime = newTime; | |
return delta; | |
}; | |
} | |
var checkInterval = interval(); | |
console.log ( checkInterval() ); | |
// do something | |
console.log ( checkInterval() ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment