Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Evaluate() slows processing?

Status
Not open for further replies.

Glowball

Programmer
Joined
Oct 6, 2001
Messages
373
Location
US
This is largely a question for tleish, is it true that the Evaluate() function slows things down? I use it because sometimes it seems that CF will toss out errors with simple math if I don't use it. I tend to slap it around all of my math so this is raising a flag with me. Is there something I should read about Evaluate()?

Thanks!
 
Don't get me wrong, there are sometimes you can't avoid using the Evaluate() function... and I only use it after exhausting all other possibilites. I can't reference anywhere in particular, but I've read several articles that talk about Evaluate() being one of the slowest functions in ColdFusion. I would use Val() for math functions in place of Evaluate... but even then, I would avoid using Val() also.

Don't take my word for it, try this bit of code below that shows the different speed of Normal, Val(), and Evalute() functions.

[COLOR=666666]<!--- If you change this from 100 to 500,
it will break Evaluate() --->
[/color]

<CFSET vLoop = 500>

[COLOR=666666]<!--- Test Normal Speed --->[/color]
[COLOR=000080]<B>[/color]Normal:[COLOR=000080]</B>[/color][COLOR=000080]<BR>[/color]
<CFSET vNumber = 1>
<CFSET start = GetTickCount()>
<CFLOOP FROM=&quot;1&quot; TO=&quot;#VARIABLES.vLoop#&quot; INDEX=&quot;i&quot;>
<CFSET vNumber = VARIABLES.vNumber * i>
</CFLOOP>
<CFSET end = GetTickCount()>
<CFSET time = VARIABLES.end - VARIABLES.start>
<CFOUTPUT>
#VARIABLES.time# milliseconds[COLOR=000080]<BR>[/color]
vNumber=#VARIABLES.vNumber#
</CFOUTPUT>
[COLOR=000080]<BR>[/color]
[COLOR=000080]<BR>[/color]

[COLOR=666666]<!--- Test the speed of Val() --->[/color]
[COLOR=000080]<B>[/color]Val():[COLOR=000080]</B>[/color][COLOR=000080]<BR>[/color]
<CFSET vNumber = 1>
<CFSET start = GetTickCount()>
<CFLOOP FROM=&quot;1&quot; TO=&quot;#VARIABLES.vLoop#&quot; INDEX=&quot;i&quot;>
<CFSET vNumber = Val(VARIABLES.vNumber * i)>
</CFLOOP>
<CFSET end = GetTickCount()>
<CFSET time = VARIABLES.end - VARIABLES.start>
<CFOUTPUT>
#VARIABLES.time# milliseconds[COLOR=000080]<BR>[/color]
vNumber=#VARIABLES.vNumber#
</CFOUTPUT>
[COLOR=000080]<BR>[/color]
[COLOR=000080]<BR>[/color]

[COLOR=666666]<!--- Test speed of Evaluate() --->[/color]
[COLOR=000080]<B>[/color]Evaluate():[COLOR=000080]</B>[/color][COLOR=000080]<BR>[/color]
<CFSET vNumber = 1>
<CFSET start = GetTickCount()>
<CFLOOP FROM=&quot;1&quot; TO=&quot;#VARIABLES.vLoop#&quot; INDEX=&quot;i&quot;>
<CFSET vNumber = Evaluate(VARIABLES.vNumber * i)>
</CFLOOP>
<CFSET end = GetTickCount()>
<CFSET time = VARIABLES.end - VARIABLES.start>
<CFOUTPUT>
#VARIABLES.time# milliseconds[COLOR=000080]<BR>[/color]
vNumber=#VARIABLES.vNumber#
</CFOUTPUT>

On my machine, I average the following output:

Normal:
20 milliseconds
vNumber=7.3621402796E+127

Val():
60 milliseconds
vNumber=7.3621402797E+127

Evaluate():
120 milliseconds
vNumber=7.3621402797E+127 - tleish
 
Interesting, thanks for taking the time to work that out. I use Evaluate() a LOT so this will be something I'll need to implement over time -- fixing things, I mean. I'm wondering what would be slower though, because now I feel like I'll need to do this:
Code:
<cftry>
<cfset someVar = VARIABLES.something + VARIABLES.somethingelse>
<cfcatch>
    <cfset someVar = Evaluate(VARIABLES.something + VARIABLES.somethingelse>
</cfcatch>
</cftry>
I'm guessing that one will be slower whether it works or not, yes? Hmm, a dilemma... because Evaluate() always works and sometimes normal math won't for some mysterious reason.

Any thoughts on that?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top