cfStopWatch on Railo

After I found the Ternary Operator on Railo I've decided to have a look over the Tags documentation, and Functions documentation viewer on Railo Wiki.

Then I came across CFStopWatch. It works like CFTimer in that its used to determine how long it takes for a block of code to execute. The difference is that CFStopWatch stores the time to execute in a variable so you can reference it later. It works by wrapping the tags around the code block you want to execute and setting the time to a variable:

[sourcecode language="plain"]<cfstopwatch label="myLabel" variable="var" > CFML logic goes here <!--- pause for 1 second ---> <cfsleep time="1000"/></cfstopwatch><cfoutput><p>Your code took #var# milliseconds to run</p></cfoutput>[/sourcecode]Running the above code will output
CFML logic goes hereYour code took 1000 milliseconds to run

I can see me using this when running code blocks which I know might take ages, you could write of the time to a log or even send an email.