Profile
From FirebugWiki
(Difference between revisions)
Sebastianz (Talk | contribs) (Separate Command Line API page for profile()) |
Sebastianz (Talk | contribs) m (Fixed link to Profiler) |
||
| (2 intermediate revisions not shown) | |||
| Line 1: | Line 1: | ||
| - | Turns | + | Turns the [[Profiler#CPU_profiling|JavaScript CPU profiler]] on, which creates detailed statistics about function calls. |
| + | |||
| + | To stop profiling use <code>[[profileEnd|profileEnd()]]</code>. | ||
| + | |||
| + | == Syntax == | ||
| + | <source lang="javascript"> | ||
| + | profile([title]) | ||
| + | </source> | ||
| + | |||
| + | == Parameters == | ||
| + | === title === | ||
| + | Summary for the profiler output. | ||
| + | |||
| + | This is displayed above the table including the statistics. | ||
| + | |||
| + | == Examples == | ||
| + | <source lang="javascript"> | ||
| + | function getById(id) | ||
| + | { | ||
| + | return document.getElementById(id); | ||
| + | } | ||
| + | |||
| + | function getViaSelector(id) | ||
| + | { | ||
| + | return document.querySelector(id); | ||
| + | } | ||
| + | |||
| + | var numberOfCalls = 10000; | ||
| + | |||
| + | console.profile("getElementById() vs. querySelector()"); | ||
| + | for (var i=0; i<numberOfCalls; ++i) | ||
| + | getById("test"); | ||
| + | for (var i=0; i<numberOfCalls; ++i) | ||
| + | getViaSelector("test"); | ||
| + | console.profileEnd(); | ||
| + | </source> | ||
| + | |||
| + | This will compare the speed of the function <code>document.getElementById()</code> with the function <code>document.querySelector()</code>. The output of that code will look like this: | ||
| + | |||
| + | [[file:profilerOutputExample.png]] | ||
| + | |||
| + | == See also == | ||
| + | * [[profileEnd]] | ||
| + | * [[Command Line API]] | ||
Latest revision as of 12:14, 18 July 2012
Turns the JavaScript CPU profiler on, which creates detailed statistics about function calls.
To stop profiling use profileEnd().
Contents |
[edit] Syntax
profile([title])
[edit] Parameters
[edit] title
Summary for the profiler output.
This is displayed above the table including the statistics.
[edit] Examples
function getById(id) { return document.getElementById(id); } function getViaSelector(id) { return document.querySelector(id); } var numberOfCalls = 10000; console.profile("getElementById() vs. querySelector()"); for (var i=0; i<numberOfCalls; ++i) getById("test"); for (var i=0; i<numberOfCalls; ++i) getViaSelector("test"); console.profileEnd();
This will compare the speed of the function document.getElementById() with the function document.querySelector(). The output of that code will look like this:
