Login Register

Profiling

Performance problems are bugs too, and Dojo has built-in facilities for identifying slow-running code segments. Some JavaScript debuggers like Firebug give file-loading performance, but often you need information at the code level.

You can cheaply calculate function execution time by taking the difference between two JavaScript dates. It's not a great technique, because you have to make educated guesses as to where the inefficient areas are, and it may take quite a lot of work to home in on the problem area. But it is easy to do if you are measuring a single function:

var startTime = new Date();
// call your function here
console.debug("Total time: " + (new Date() - startTime));

Another example of code to do this is on this page.

we should probably suggest using console.* instead

and also point out that other tools now provide method-level profiling (Venkman, Firebug... others?)