Profiling
Submitted by Carla on Sat, 05/12/2007 - 15:08.
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));
// call your function here
console.debug("Total time: " + (new Date() - startTime));
Another example of code to do this is on this page.
- Printer-friendly version
- Login or register to post comments
- Subscribe post
we should probably suggest using console.* instead
and also point out that other tools now provide method-level profiling (Venkman, Firebug... others?)