Practical Web Programming

Wednesday, February 29, 2012

Javascript: How to Get Code Execution Time Using Firebug

So you're curious how much time your Javascript code takes time to finish execution. If you're using Firefox, Firebug is your best friend.

Let me show in the following example.


console.time('for loop');

for (i = 0; i < 1000000; i++) {
// do nothing.
}

console.timeEnd('for loop');


To see the console, open Firebug in Firefox, then go to Console tab. If you don't have an HTML page where to put the Javascript code, you can go to http://jsfiddle.net and paste it there.

0 comments:

Recent Post