cftimer

Description

Displays execution time for a specified section of CFML code. ColdFusion MX displays the timing information along with any output produced by the timed code.

Note: To permit this tag to execute, enable the Enable Debugging and the Timer Information options on the Debugging Settings page in the ColdFusion Administrator. Also, the IP address of the machine that runs ColdFusion must be added to the list of debugging IP addresses in the Debugging IP Addresses page if the request is sent by a remote machine. If the request is from a localhost, the IP address 127.0.0.1 must be present in the list of debugging IP addresses.

Syntax

<cftimer 
    label= "text" 
    type = "inline|outline|comment|debug" > 
 
    CFML statement(s) 
 
</cftimer>
Note: You can specify this tag’s attributes in an attributeCollection attribute whose value is a structure. Specify the structure name in the attributeCollection attribute and use the tag’s attribute names as structure keys.

See also

cfdump, cftrace; Debugging and Troubleshooting Applications in the Developing ColdFusion Applications

History

ColdFusion MX 7: Added this tag.

Attributes

Attribute

Req/Opt

Default

Description

label

Optional

" "

Label to display with timing information.

type

Optional

debug

  • inline: displays timing information inline, following the resulting HTML.

  • outline: displays timing information and also displays a line around the output produced by the timed code. The browser must support the FIELDSET tag to display the outline.

  • comment: displays timing information in an HTML comment in the format <!-- label: elapsed-time ms -->. The default label is cftimer.

  • debug: displays timing information in the debug output under the heading CFTimer Times.

Usage

Use this tag to determine how long it takes for a block of code to execute. You can nest cftimer tags.

This tag is useful for debugging CFML code during application development. In production, you can leave cftimer tags in your code as long as you have disabled the debugging option in the ColdFusion Administrator.

Example

... 
<!--- type="inline"> ---> 
    <cftimer label="Query and Loop Time Inline" type="inline"> 
        <cfquery name="empquery" datasource="cfdocexamples"> 
            SELECT * 
            FROM Employees 
        </cfquery> 
 
        <cfloop query="empquery"> 
        <cfoutput>#lastname#, #firstname#</cfoutput><br> 
        </cfloop> 
    </cftimer> 
<hr><br> 
 
<!--- type="outline" ---> 
    <cftimer label="Query and CFOUTPUT Time with Outline" type="outline"> 
        <cfquery name="coursequery" datasource="cfdocexamples"> 
            SELECT * 
            FROM CourseList 
        </cfquery> 
    <table border="1" width="100%"> 
        <cfoutput query="coursequery"> 
        <tr> 
        <td>#Course_ID#</td> 
        <td>#CorName#</td> 
        <td>#CorLevel#</td> 
        </tr> 
        </cfoutput> 
        </table> 
    </cftimer> 
<hr><br> 
 
<!--- type="comment" ---> 
    <cftimer label="Query and CFOUTPUT Time in Comment" type="comment"> 
        <cfquery name="parkquery" datasource="cfdocexamples"> 
                SELECT * 
                FROM Parks 
        </cfquery> 
<p>Select View &gt; Source to see timing information</p> 
    <table border="1" width="100%"> 
        <cfoutput query="parkquery"> 
        <tr> 
        <td>#Parkname#</td> 
        </tr> 
        </cfoutput> 
        </table> 
    </cftimer> 
<hr><br> 
 
<!--- type="debug" ---> 
    <cftimer label="Query and CFOUTPUT Time in Debug Output" type="debug"> 
        <cfquery name="deptquery" datasource="cfdocexamples"> 
                SELECT * 
                FROM Departments 
        </cfquery> 
<p>Scroll down to CFTimer Times heading to see timing information</p> 
    <table border="1" width="100%"> 
        <cfoutput query="deptquery"> 
        <tr> 
        <td>#Dept_ID#</td> 
        <td>#Dept_Name#</td> 
        </tr> 
        </cfoutput> 
        </table> 
    </cftimer> 
...