Skip to content

Instantly share code, notes, and snippets.

@erkarp
Created January 30, 2018 15:33
Show Gist options
  • Save erkarp/2b6a0fcd20713b694b4cd6381392a49a to your computer and use it in GitHub Desktop.
Save erkarp/2b6a0fcd20713b694b4cd6381392a49a to your computer and use it in GitHub Desktop.
JavaScript Console Timer
function createTimer() {
var start = (new Date()).valueOf()/1000;
return {
timestamp: function() {
var stamp = Math.floor((new Date()).valueOf()/1000 - start);
console.log('Timestamp:', stamp, 'seconds.', [].slice.call(arguments).join(' '));
}
}
}
// Usage example:
var foo = createTimer();
['1st', '2nd', '3rd'].forEach(function(value, index)
{
setTimeout(function()
{
foo.timestamp('value:', value);
}, ++index * 30s00);
});
foo.timestamp('beginning');
// console output:
// Timestamp: 0 seconds. beginning
// Timestamp: 3 seconds. value: 1st
// Timestamp: 6 seconds. value: 2nd
// Timestamp: 9 seconds. value: 3rd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment