
390
DEVELOPING
COLDFUSION 9 APPLICATIONS
Developing CFML Applications
Las
t
upda
te
d 8/5/2010
Using timing
Use this tag to determine how long it takes for a block of code to execute. This is useful when ColdFusion debugging
output indicates excessive execution time, but does not pinpoint the long-running block of code.
To use this tag, enable debugging in the ColdFusion 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.
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.
Calling the cftimer tag
You can control where the
cftimer
tag displays timing information, as follows:
•
Inline
: Displays timing information following the
</cftimer>
tag.
•
Outline
: Displays timing information at the beginning of the timed code and draws a box around the timed code.
(This requires browser support for the HTML FIELDSET attribute.)
•
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 debugging output under the heading CFTimer Times.
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>