Prove that coldfusion functions unnecessarily buffer with output = true

I heard that if you do not specify output="false"in the ColdFusion function that unnecessary buffering will occur, which may interfere with the work. So I wanted to run a test to check if I can prove it. My test is below. I did not see the difference between output="true"or output="false".

So my question is: if I have functions used in large loops, do I need 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 completed in exactly 20-21 seconds.

enter image description here

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>
--->
+4
1

, output = "false" , ( Application.cfc, onRequest(), ). , - , - , , . , , , ( ).

:

<cffunction name="getFlag" output="true">
    <cfreturn true />
</cffunction>

<cfif getFlag()><p>Hello World!</p></cfif>

<cfxml variable="doc"><cfoutput><root flag="#getFlag()#" /></cfoutput></cfxml>

<cfif doc.root.xmlAttributes.flag><p>Hello world!</p></cfif>

- , , , <cfif> , XML-, <cfdump>. , :

cannot convert the value " true" to a boolean 

XML, CF "true" , "true". , , , , XML , . , CF5.;)

+3

Source: https://habr.com/ru/post/1532334/


All Articles