I've heard that if you do not specify output="false"
on a ColdFusion function that unnecessary buffering would occur which could hinder performance. So I wanted to run a test to see if I could prove this. My test is below. I saw no difference at all between output="true"
or output="false"
.
So my question is: if I have functions used within large loops should I not have to worry about this setting? Or am I not testing this correctly?
My test was to call the same function 1,000,000 times. I ran it 3 times with output="false"
and 3 times with output="true"
. All 6 tests finished at exactly 20-21 seconds.
The Test Code:
<cffunction name="good" output="false" returntype="Numeric" access="private">
<cfargument name="numIn" type="numeric" required="true">
<cfset var x = 0>
<cfset x = arguments.numIn + 1>
<cfreturn x>
</cffunction>
<cffunction name="bad" output="true" returntype="Numeric" access="private">
<cfargument name="numIn" type="numeric" required="true">
<cfset var x = 0>
<cfset x = arguments.numIn + 1>
<cfreturn x>
</cffunction>
<cfset loopNum = 1000000>
<cfset x = 0>
<cfoutput>
x = #x#<br>
Running bad function #loopNum# times...<br>
</cfoutput>
<cfset tBegin = GetTickCount()>
<cfloop from="1" to="#loopNum#" index="i">
<cfset x = bad(i)>
</cfloop>
<cfset tEnd = GetTickCount()>
<cfset scriptTime = (tEnd - tBegin)>
<cfoutput>
x = #x#<br>
Time to complete: #scriptTime#<br>
</cfoutput>
<!---
<cfset x = 0>
<cfoutput>
x = #x#<br>
Running good function #loopNum# times...<br>
</cfoutput>
<cfset tBegin = GetTickCount()>
<cfloop from="1" to="#loopNum#" index="i">
<cfset x = good(i)>
</cfloop>
<cfset tEnd = GetTickCount()>
<cfset scriptTime = (tEnd - tBegin)>
<cfoutput>
x = #x#<br>
Time to complete: #scriptTime#<br>
</cfoutput>
--->