Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Simple timer with javascript
var timer = {
started: 0,
end: 0,
now: function(){ return new Date(); },
start: function(){ return this.started = this.now(); },
since: function(){ this.end = this.now(); return this.now()-this.started; }
}
// Usage:
console.log("Timer started at "+timer.start());
for(x=1;x<100000;x++){
// Something
}
console.log("Some process: " + timer.since() + "ms");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.