programming.torensma.net: Code Snippets

Simple JavaScript execution timer

/**
* Simple JavaScript execution timer
* http://programming.torensma.net
*
* Example:
* scriptTimer.startTimer();
* alert('Hello world!');
* scriptTimer.stopTimer();
* alert(scriptTimer.scriptRunTime);
*/

var scriptTimer = {
    scriptRunTime : 0,
    startTime : 0,
    stopTime : 0,
    startTimer : function(){
        time = new Date();
        this.startTime = time.getTime();
    },
    stopTimer : function(){
        time = new Date();
        this.stopTime = time.getTime();
        this.scriptRunTime = (this.stopTime - this.startTime)/1000;
    }
}

You can follow any responses to this entry through the RSS 2.0 feed.