Skip to content

Instantly share code, notes, and snippets.

@jamestomasino
Last active December 10, 2015 02:38
Show Gist options
  • Save jamestomasino/4369616 to your computer and use it in GitHub Desktop.
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.
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