在我的测试盒上,我有 ColdFusion 10 并且只分配了 1gig:“最大 JVM 堆大小(以 MB 为单位)= 1024”。
我有一个循环大约 1000 次的过程。每次循环迭代调用一个自定义标签约 200 次。所以总共有大约 200,000 个电话。这个过程永远不会结束,我最终内存不足。我确定这是我在标签内所做的事情,而不是标签本身。但我想证明这一点。我运行了这个测试,似乎 ColdFusion 函数2.7secs
比14.6secs
. 测试只是增加一个数字。
我的问题是:这似乎是一个有效的测试吗? 如果函数要快得多,是否应该尽可能地使用它们而不是自定义标签?
试验结果:
x = 0
Running good customtag 1000000 times...
x = 1000000
Time to complete: 14627
x = 0
Running good function 1000000 times...
x = 1000001
Time to complete: 2793
good.cfm 自定义标签:
<cfparam name="ATTRIBUTES.x" type="numeric" default="0">
<cfif thisTag.ExecutionMode eq "end">
<cfset request.x = ATTRIBUTES.x+1>
<cfset thistag.generatedcontent = "">
</cfif>
测试代码:
<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>
<cfset loopNum = 1000000>
<cfset request.x = 0>
<cfoutput>
x = #request.x#<br>
Running good customtag #loopNum# times...<br>
</cfoutput>
<cfset tBegin = GetTickCount()>
<cfloop from="1" to="#loopNum#" index="i">
<cf_good x="#request.x#"></cf_good>
</cfloop>
<cfset tEnd = GetTickCount()>
<cfset scriptTime = (tEnd - tBegin)>
<cfoutput>
x = #request.x#<br>
Time to complete: #scriptTime#<br>
</cfoutput>
<cfset request.x = 0>
<cfoutput>
x = #request.x#<br>
Running good function #loopNum# times...<br>
</cfoutput>
<cfset tBegin = GetTickCount()>
<cfloop from="1" to="#loopNum#" index="i">
<cfset request.x = good(i)>
</cfloop>
<cfset tEnd = GetTickCount()>
<cfset scriptTime = (tEnd - tBegin)>
<cfoutput>
x = #request.x#<br>
Time to complete: #scriptTime#<br>
</cfoutput>