You can!
An example:
if (window.console && window.console.profile) {
console.profile("label for profile");
// insert code to profile here,
// all function calls will be profiled
console.profileEnd();
}
It also works on Safari, and with Firebug in Firefox.
Note: You can’t use profile to time code that does not make a function call: if your code above is simply a for loop then the profiler won’t find anything to profile. Use console.time()
and console.timeEnd()
to benchmark pure loops or code that does not call a function.