My CFTIMER Custom Tag
I had been meaning to write a custom tag for timing ColdFusion code execution for some time when <cftimer> finally showed up. Well, I was excited about this small addition to the CF tag library. That is, until I put it in my code and then saw nothing. That's when I read a little more and discovered that you have to turn the tag on in the debugging setting in the ColdFusion Administrator. And you have to have debugging on while you are using it.
"Sheesh!", I exclaimed. I sort of understand why they might only show it in debugging mode. (So, that you can leave it in and deploy.) However, I don't work in debugging mode. And I only add in debugging code when I need it and then clean it up. Otherwise you have code that is riddled with debugging code and comments. Yuck!
So, that was it. I decided to write a custom tag to fit my needs. You can get that here. There is as much documentation as you would need in the mytimer.cfm. It currently only emulates the "inline" mode of the official cftimer. However you can easily emulate the "comment" mode by wrapping the closing tag in an HTML comment.
Plus it has one extra feature that I heard other people ask for. A "variable" attribute that, instead of outputting the results, puts the number of milliseconds into the variable of your choice.
See below for that syntax:
<cf_mytimer variable="time2wait">
<cfset CreateObject('java','java.lang.Thread').sleep(300) />
</cf_mytimer>
<cfoutput>time2wait = #time2wait# ms</cfoutput>
I hope someone else finds this useful. And again, you can get that here.

There are no comments for this entry.
[Add Comment]