Created
January 30, 2018 15:33
-
-
Save erkarp/2b6a0fcd20713b694b4cd6381392a49a to your computer and use it in GitHub Desktop.
JavaScript Console Timer
This file contains hidden or 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 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