Search This Blog

Tuesday, June 4, 2013

ColdFusion: CFTIMER vs. getTickCount()

In the old days, to measure how long a block of ColdFusion code is executed, we would use getTickCount(). Get the tick before and after the code in question; and subtract them. Newer versions of ColdFusion provide an alternative way to do the specified job. Wrap the code with <cftimer>...</cftimer>.
There is a downside using the tag, you will need to Enable Request Debugging Output in CF Admin. I also found that the "type" attribute is required instead of optional as stated on the documentation. It does not give us an error, but it will not show any results.

<cftimer type="outline">

 <cfset i = 1 />
 <cfloop index="i" from="1" to="100">
  <cfset i = i + 1 /> 


NOTE: I knew that we could use i++ or incrementValue(i), but I just wanted to use i=i+1 for clarity. :)