Simple Javascript Timer

Sometime we may need to create a timer to count how long the javascript is perform from begin and end. Below is a simple code that give a little help.

var timer = {

    start: function() {
       this.begin = new Date().valueOf();
    },
    stop : function() {
       return new Date().valueOf() - this.begin;
    }

}

Usage

var timer = {

    start: function() {
       this.begin = new Date().valueOf();
    },
    stop : function() {
       return new Date().valueOf() - this.begin;
    }
}

timer.start();

var x = 0;
for ( i = 0; i < 100000; i ++) {
    x = i+i * (2);
}
console.log("x = " + x);

timer.stop();

 

Simple Javascript Timer

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.