CURRENT PROJECTS
loading
CATEGORIES AND POSTS
loading
overset
DEVELOPMENT LOG FOR JIM PALMER
Posted 03/17/2008 in coldfusion


There is a definite penalty to using the "Report Execution Times" in the coldfusion administrator. There is a simple way to use built-in java timestamps to guage execution time.

I simply add a start time at the beginning of a request via the Application.cfc's onRequest method and calculate the difference in time at the end of the Application.cfc's onRequestEnd method as follows:
<cfcomponent>
	<cffunction name="onRequest" returnType="void">
		<cfargument type="String" name="targetPage" required=True>
		<!--- start execution time --->
		<cfset jDate = createObject("java", "java.util.Date")>
		<cfset __execStart = jDate.getTime()>
	</cffunction>
	<cffunction name="onRequestEnd" output="Yes"><cfsetting enablecfoutputonly="Yes">
		<cfset pageContent = getPageContext().getOut().getString()>
		<cfset getPageContext().getOut().clearBuffer()>
		<!--- end execution time --->
		<cfset jDate = createObject("java", "java.util.Date")>
		<cfset __execEnd = jDate.getTime()>
		<cfset pageContent = pageContent & "<br>" & (__execEnd - __execStart) & "ms">
	</cffunction>
</cfcomponent>

This is using the built-in java Date object which includes the "unix" time-stamp number of milliseconds since the unix epoc which is perfect for calculating execution time. For each run of the application 2 java Date objects are instantiate within the request scope which is only a minute amount of overhead. This method could possibly be made faster if instantiating a Date object at the Application level and only setting the actual current time at the start and end of a request, but this has proved itself as fast enough in the production environment.
comments
loading
new comment
NAME
EMAIL ME ON UPDATES
EMAIL (hidden)
URL
MESSAGE TAGS ALLOWED: <code> <a> <pre class="code [tab4|tabX|inline|bash]"> <br>
PREVIEW COMMENT
TURING TEST
gravatar