This page describes how to use the Firebug extension for Firefox to profile code performance for a web page.
Contents |
Introduction
The Firebug console provides you with three ways to detect performance problems in your code:
- Determining how long a function takes to execute
- Running a code profile on a script
- Running a code profile on specific blocks of code
Instructions
Determining how long a function takes to execute
The simplest way to identify a performance issue is to determine how long a suspicious function takes to run. To determine how long a function is taking to execute:
- Add a
console.time()
function just before the function. - Add a
console.timeEnd()
function just after the function.
This will give you the start and end time for the execution of the function.
Running a code profile on a script
If you have no idea which functions are causing performance issues in your code, you can create a Profile report in Firebug to help you troubleshoot.
To create a Profile report:
- Click the tab.
- Click the button to start the profiler.
- Click the button again to stop the profiler.
The console will display the Profile report for your code.
Running a code profile on specific blocks of code
You can also create a targeted profile report by creating a profile for a specific block of code. To create a profile for a specific block of code:
- Add a
console.profile()
function just before the function. - Add a
console.profileEnd()
function just after the function.