|
Mailing Lists
|
Home /
Groups /
ColdFusion Talk (CF-Talk)
Interesting results with setting variables - cfset vs using a cfscript block
Author: Dominic Watson
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:56904#308482
>In the end it depends on personal style, readability and other user factors
as to which is preferred when setting large blocks of variables..
Yes absolutely ;)
Dominic
----- Excess quoted text cut - see Original Post for more -----
Author: Larry Lyons
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:56904#308481
thanks dominic,
I ran your code and the results between setting variable blocks with cfscript or
using cfset varied from trial to trial. Some times cfscript was faster, other
times cfset.
Anyhow in a nutshell it confirms my initial idea, that it isn't really a major
issue. In the end it depends on personal style, readability and other user
factors as to which is preferred when setting large blocks of variables..
regards,
larry
----- Excess quoted text cut - see Original Post for more -----
Author: Pete Jordan
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:56904#308463
Stephane Vantroyen wrote:
> You should read this, quite interesting (CF8 vs CF7 etc) : http://neilmiddleton.com/2007/07/01/cf-8-and-performance-comparisons/
My guess is that a lot (most?) of the runtime difference between CF7 and
8 is down to the JVM; Java 6 is faster than 5 and a *lot* faster than 4.
FWIW, we're running both CF7 and 8. and have run 7 with (Sun) Java 6
pretty much since it released, without any problems at all: I'd guess
that macradobe warnings on that are mostly to cover themselves.
--
Regards,
Pete Jordan
Horus Web Engineering Ltd
http://www.webhorus.net/
phone: +44 1275 543971
mobile: +44 7973
725120
Author: Claude Schneegans
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:56904#308456
Note that
1º according to the docs, GetTickCount() returns "a string
representation of the system time,"
not the time spent on the CF code.
The CF server is running in a time shared environment, so the system
time is not really representative
of the execution time.
2º There is a huge difference between what fellow developers think how
things should be logically in theory and how they really are in practice ;-)
--
_______________________________________
REUSE CODE! Use custom tags;
See http://www.contentbox.com/claude/customtags/tagstore.cfm
(Please send any spam to this address: piegeacon@internetique.com)
Thanks.
Author: Dominic Watson
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:56904#308447
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
----- Excess quoted text cut - see Original Post for more -----
Author: Stephane Vantroyen
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:56904#308446
You should read this, quite interesting (CF8 vs CF7 etc) : http://neilmiddleton.com/2007/07/01/cf-8-and-performance-comparisons/
Regards,
Stephane
Author: Larry Lyons
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:56904#308445
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?
|
May 24, 2012
|
Latest Fusion Authority Articles
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||