View comments | RSS feed

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, you must enable the Timer Information option under Debugging Settings in the ColdFusion MX Administrator.

Category

Debugging tags

Syntax

<cftimer
   label= "text"
   type = "inline" or "outline" or "comment" or "debug" >

   CFML statement(s)

</cftimer>

See also

cfdump, cftrace; Debugging and Troubleshooting Applications in ColdFusion MX Developer's Guide

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 <!-- labelelapsed-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 MX Administrator.

Example1

...
<!--- 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>
...

ColdFusion 9 | ColdFusion 8 | ColdFusion MX 7 | ColdFusion MX 6.1 | ColdFusion MX | Forums | Developer Center | KnowledgeBase | Bug Reporting

Version 7

Comments


bsimmons said on Jun 26, 2005 at 2:39 PM :
The page mentions that you have to check the "Timer Information" checkbox under the Debugging Settings in the Admin. However, it fails to mention that you also need to check the "Enable Debugging" checkbox. Is this an oversight in the docs, or should this tag work without enabling debugging?
It seems like being able to use the <CFTIMER> tag without having to Enable Debugging would be incredibly useful.
Or perhaps I'm missing something....
bizarrojack said on Aug 10, 2005 at 5:06 PM :
File this under likely-useless trivia:

Ironically, if you are using cftimer a lot, counting milliseconds and perhaps nesting cftimers, you may notice that cftimer can add perhaps 20 milliseconds to the total execution time of the page. It seems to be either 2ms or 20ms on my test system, depending on what, I do not know for sure, but nesting of cftimer seems to be a factor. So you might want to think about that if you are hunting down a speed problem and using a lot of cftimers . . . you could see your total execution time growing even as you are collecting speed data.
It is a debug tag and hopefully won't have a role in delivered applications, anyway.

To the previous poster, Yes, this is definitely only relevant to debugging mode. I'm sure there is a way to get hi res clock measurements for use in an application, but I don't know it yet. At worst, I am sure it could be done using cfimport and a java object.
ASandstrom said on Aug 18, 2006 at 1:11 PM :
You do have to select the Enable Debugging option in the CF Administrator to enable this tag. This will be added to the next version of the documentation.
Tones411 said on Dec 5, 2008 at 10:22 AM :
Use GetTickCount() instead. See: http://www.petefreitag.com/item/227.cfm

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/coldfusion/7/htmldocs/00000344.htm