The reason is that you’re using CFSET and evaluating to a dummy variable (test), wasting some overhead and memory – I added to your test code, seeing what CFScript’s performance would be:

 

<cfset startTime = getTickCount()>

<cfloop from="1" to="1000" index="i">

 <cfset varName = "dynamicVar1#i#">

 <cfset "dynamicVar#i#" = i>

</cfloop>

<cfset endTime = getTickCount()>

<cfset totalTime = endTime - startTime>

<cfoutput>using the quote and pound method = #totalTime#</cfoutput><br>

 

 

<cfset startTime = getTickCount()>

<cfloop from="1" to="1000" index="i">

 <cfset varName = "dynamicVar2#i#">

 <cfset temp = setVariable("dynamicVar" & i, i)>

</cfloop>

<cfset endTime = getTickCount()>

<cfset totalTime = endTime - startTime>

<cfoutput>using the concat setVariable() method = #totalTime#</cfoutput><br>

 

 

<cfset startTime = getTickCount()>

<cfloop from="1" to="1000" index="i">

 <cfset varName = "dynamicVar3#i#">

 <cfset temp = setVariable(varName, i)>

</cfloop>

<cfset endTime = getTickCount()>

<cfset totalTime = endTime - startTime>

<cfoutput>using setVariable() with plain variable for the name = #totalTime#</cfoutput><br>

 

 

<cfset startTime = getTickCount()>

<cfloop from="1" to="1000" index="i">

 <cfset varName = "dynamicVar3#i#">

 <cfscript>setVariable(varName, i);</cfscript>

</cfloop>

<cfset endTime = getTickCount()>

<cfset totalTime = endTime - startTime>

<cfoutput>using setVariable() with plain variable for the name (cfscript) = #totalTime#</cfoutput><br>

 

Here were my results:

 

using the quote and pound method = 220
using the concat setVariable() method = 260
using setVariable() with plain variable for the name = 231
using setVariable() with plain variable for the name (cfscript) = 200

 

---
Billy Cravens

 

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] On Behalf Of Nate Nielsen
Sent: Wednesday, February 20, 2002 5:54 PM
To: [EMAIL PROTECTED]
Subject: Re: Settings vars with an index loop

 

FYI, use <cfset "static#dyanmic#" = 1234> for setting dynamic variables, for some reason its the fastest way to do so.

 

Easy, yes.

Ugly, surely.

*but sadly, the fastest :

 

<cfset startTime = getTickCount()>
<cfloop from="1" to="1000" index="i">
 <cfset varName = "dynamicVar1#i#">
 <cfset "dynamicVar#i#" = i>
</cfloop>
<cfset endTime = getTickCount()>
<cfset totalTime = endTime - startTime>
<cfoutput>using the quote and pound method = #totalTime#</cfoutput><br>

<cfset startTime = getTickCount()>
<cfloop from="1" to="1000" index="i">
 <cfset varName = "dynamicVar2#i#">
 <cfset temp = setVariable("dynamicVar" & i, i)>
</cfloop>
<cfset endTime = getTickCount()>
<cfset totalTime = endTime - startTime>
<cfoutput>using the concat setVariable() method = #totalTime#</cfoutput><br>

<cfset startTime = getTickCount()>
<cfloop from="1" to="1000" index="i">
 <cfset varName = "dynamicVar3#i#">
 <cfset temp = setVariable(varName, i)>
</cfloop>
<cfset endTime = getTickCount()>
<cfset totalTime = endTime - startTime>
<cfoutput>using setVariable() with plain variable for the name = #totalTime#</cfoutput><br>

yields:

 

using the quote and pound method = 531
using the concat setVariable() method = 611
using setVariable() with plain
variable for the name = 571

 

Is that frustrating to anyone else besides me?   I know is hardly a difference, but the point being that is <i>should</i> be faster, not slower.  I hate how the functions in CF can sometimes return slower results than dummy code:  10,000 itterations of var + 1 vs. incrementValue(var)

 

var + 1 = 1783
incrementValue(var) = 2063

 

ugggg.  Dont ya just FEEL like a noob writing <cfset loopcount = loopcount + 1> ?

 

lol.

 

Nate Nielsen

817.726.8644

 

----- Original Message -----

Sent: Wednesday, February 20, 2002 3:41 PM

Subject: RE: Settings vars with an index loop

 

Hi gary

you can try this.

<cfloop index="i" from="1" to="5">
 <cfset temp = SetVariable("Value"&i, x)>
 <cfoutput>#Evaluate("Value"& i)#<br></cfoutput>
</cfloop>

-Balaji

From: "Billy Cravens"

<[EMAIL PROTECTED]>

Reply-To: [EMAIL PROTECTED]

To:

<[EMAIL PROTECTED]>

Subject: RE: Settings vars with an index loop

Date: Wed, 20 Feb 2002 14:10:28 -0600

That won't work - Gary's wanting the variable name to be dynamic, not

assign the value to a pre-known name (in your example, var1). Your

example only assigns a value to var1, then reassigns a value to it. If

you did #myvar1# (as Gary wants to do), you'd throw

an exception - instead, do:

---

Billy Cravens

-----Original Message-----

From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] On

Behalf Of Ron Mast

Sent: Wednesday, February 20, 2002 1:28 PM

To: '[EMAIL PROTECTED]'

Subject: RE: Settings vars with an index loop

Try this:

#var1#

Ron

-----Original Message-----

From: Houk, Gary [mailto:[EMAIL PROTECTED]]

Sent: Wednesday, February 20, 2002 1:22 PM

To: [EMAIL PROTECTED]

Subject: Settings vars with an index loop

Is there a way I can say:

by looping over it:

I know that above code fails, but that's the idea of what I'm trying to

get.

How can I do this?

TIA,

- Gary

------------------------------------------------------------------------

-

This email server is running an evaluation copy of the MailShield anti-

spam

software. Please contact your email administrator if you have any

questions

about this message. MailShield product info: www.mailshield.com

-----------------------------------------------

To post, send email to [EMAIL PROTECTED]

To subscribe / unsubscribe: http://www.dfwcfug.org

------------------------------------------------------------------------

-

This email server is running an evaluation copy of the MailShield anti-

spam software. Please contact your email administrator if you have any

questions about this message. MailShield product info:

www.mailshield.com

-----------------------------------------------

To post, send email to [EMAIL PROTECTED]

To subscribe / unsubscribe: http://www.dfwcfug.org

-------------------------------------------------------------------------

This email server is running an evaluation copy of the MailShield anti-

spam software. Please contact your email administrator if you have any

questions about this message. MailShield product info: www.mailshield.com

-----------------------------------------------

To post, send email to [EMAIL PROTECTED]

To subscribe / unsubscribe: http://www.dfwcfug.org



MSN Photos is the easiest way to share and print your photos: Click Here
------------------------------------------------------------------------- This email server is running an evaluation copy of the MailShield anti- spam software. Please contact your email administrator if you have any questions about this message. MailShield product info: www.mailshield.com

Reply via email to