The cftimer
tag displays execution time for a specified section of CFML code.
Use this tag to determine how long it takes for a block of code to execute. This is particularly useful when ColdFusion debugging output indicates excessive execution time, but does not pinpoint the long-running block of code.
To use this tag, you must enable debugging in the ColdFusion MX Administrator Debugging Settings page. In the Debugging Settings page, you must also specifically enable usage of the cftimer
tag by checking the Timer Information check box.
Tip: If you enable debugging for the cftimer
tag only and display timing information in an HTML comment, you can generate timing information without disturbing production users.
You can control where the cftimer
tag displays timing information, as follows:
</cftimer>
tag.
<!--
label:
elapsed-time ms -->
. The default label is cftimer
.
The following example calls the cftimer
tag multiple times, each time using a different type
attribute:
<HTML> <body> <h1>CFTIMER test</h1> <!--- 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 > 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> </body>