Created
April 23, 2014 04:24
-
-
Save victornpb/11202690 to your computer and use it in GitHub Desktop.
Stopwatch constructor to measure the elapsed time
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
/** Stopwatch constructor to measure the elapsed time | |
* @author Victor B - www.vitim.us | |
*/ | |
function Stopwatch(){ | |
this.running = false; | |
this.startTimestamp; | |
this.endTimestamp; | |
} | |
Stopwatch.prototype.start = function(){ | |
this.running = true; | |
return this.startTimestamp = this.endTimestamp = Date.now(); | |
} | |
Stopwatch.prototype.stop = function(){ | |
this.running = false; | |
this.endTimestamp = Date.now(); | |
return this.endTimestamp; | |
} | |
Stopwatch.prototype.elapsed = function(){ | |
if(this.running) this.endTimestamp = Date.now(); | |
return this.endTimestamp - this.startTimestamp; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment