Console.profile

From FirebugWiki
Revision as of 17:13, 21 November 2013 by Sebastianz (Talk | contribs) (Added categories)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Turns the JavaScript CPU profiler on, which creates detailed statistics about function calls.

To stop profiling use console.profileEnd().

Syntax[edit]

console.profile([title])

Parameters[edit]

title[edit]

Summary for the profiler output.

This is displayed above the table including the statistics.

Examples[edit]

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:

ProfilerOutputExample.png

See also[edit]