I ran your code a few times on my machine (XP Pro) and got varying
results; sometimes the cfscript was faster, sometimes cfset. Try this
code out instead, it performs a single test on both cfscript and cfset
for each iteration and records a tally of the time taken for each -
this spreads the test and reduces variance due to the varying state of
the computers processor, etc. So far I always have cfscript as
slightly faster:
<cfset iterations = 1000000/>
<cfset scriptTotal = 0>
<cfset cfsetTotal = 0>
<cfset scriptResult = 0 />
<cfset cfsetResult = 0 />
<cfloop from="1" to="#iterations#" index="i">
<cfset tick = getTickCount()>
<cfset cfsetResult = cfsetResult + i />
<cfset cfsetTotal = cfsetTotal + (getTickCount() - tick)>
<cfscript>
tick = getTickCount();
scriptResult = scriptResult + i;
scriptTotal = scriptTotal + (getTickCount() - tick);
</cfscript>
</cfloop>
<fieldset>
<legend>CFSCRIPT</legend>
<p><cfoutput>#scriptResult#</cfoutput><br/>
<cfoutput>Execution Time: #scriptTotal#ms</cfoutput></p>
</fieldset>
<fieldset>
<legend>CFSET</legend>
<p><cfoutput>#cfsetResult#</cfoutput><br/>
<cfoutput>Execution Time: #cfsetTotal#ms</cfoutput></p>
</fieldset>
Dominic
2008/7/2 Larry Lyons <[EMAIL PROTECTED]>:
>
> I had originally posted this on CF-Community, but I thought that these
> results were interesting enough that others would like to see them. I got
> into a discussion at my new job about creating variables by the cfset tag or
> via a variable assignment using cfscript. The consensus has been that when
> setting large blocks of variables using cfscript is faster than cfset. The
> reason that tags are slower is that when the template JITs, it adds extra
> libraries into the class. When you use cfscript,it uses fewer cftag libraries
> mentioned as Java import namespaces because the cfscript code is closer to
> the native Java and therefore requires less overhead (at least according to
> some blog postings I've read). Also, the tag named import also contains
> functionality the code may not be using. Therefore, you have thinner JITs and
> faster code. Or so I thought. Here's some code I wrote to test this, not that
> this is over a million iterations, a pretty unreal situation ordinarily:
>
> <cfset iterations = 1000000/>
> <cfscript>
> start1 = getTickCount();
> result=0;
> for(i=0;i lte #iterations#;i=i+1) {
> result=result+i;
> }
> end1 = getTickCount();
> </cfscript>
>
> <cfset start2 = getTickCount() />
> <cfset result2 = 0 />
> <cfloop from="1" to="#iterations#" index="j">
> <cfset result2=result2+j />
> </cfloop>
> <cfset end2 = getTickCount() />
>
> <fieldset>
> <legend>CFSCRIPT</legend>
> <p><cfoutput>#result#</cfoutput><br/>
> <cfoutput>Execution Time: #end1 - start1#ms</cfoutput></p>
> </fieldset>
>
> <fieldset><legend>CFSET</legend>
> <p><cfoutput>#result2#</cfoutput><br/>
> <cfoutput>Execution Time: #end2 - start2#ms</cfoutput></p>
> </fieldset>
>
> Here are the results:
> CFSCRIPT
> total: 500000500000
> Execution Time: 1472ms
>
> CFSET
> total: 500000500000
> Execution Time: 947ms
>
> So am I missing something here? This was on a Windows XP box with service
> pack 2 installed (dell optiplex dual core with 2 gigs of ram). Its running
> the dev edition of CFMX 7.02 with cumulative hotfix 3 installed. I got
> similar results using Open BlueDragon on a MacBook with OSX 10.5.3. Generally
> these results go against what's commonly thought. However given that there
> was only about a half second difference over a million iterations, is it
> really an important difference?
>
>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to
date
Get the Free Trial
http://ad.doubleclick.net/clk;203748912;27390454;j
Archive:
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:308447
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4