All,
 
Thanks for all of the replies - I not only got everything working, but perhaps I'll be able to speed it up now!
 
As always, this list rocks!
 
- Gary
-----Original Message-----
From: Nate Nielsen [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, February 20, 2002 10:54 PM
To: [EMAIL PROTECTED]
Subject: Re: Settings vars with an index loop

Touche'    
 
But when changing the ugly method to cfscript and evaluating it as well . . .   heheh
 
The below does all three tests against the two different methods and tables it.... and apples to apples, errr...- cfscript to cfscript even, the ugly method almost always (at least 95%+ of the time) shows measurably faster results (seen up to 50%+ faster). 
 
*sigh*        noob code for us all !!       =P 
 
 
Nate Nielsen
817.726.8644
 
 
The code:       (*sniffle*)
 
<cfset uglyList=''>
<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 uglyList = ListAppend(uglyList, totalTime)>
 
<cfset startTime = getTickCount()>
<cfloop from="1" to="1000" index="i">
 <cfset varName = "dynamicVar4#i#">
 <cfset "#varName#" = i>
</cfloop>
<cfset endTime = getTickCount()>
<cfset totalTime = endTime - startTime>
<cfoutput>using the quote and pound method with plain variable for the name = #totalTime#</cfoutput><br>
<cfset uglyList = ListAppend(uglyList, totalTime)>
 
<cfset startTime = getTickCount()>
<cfloop from="1" to="1000" index="i">
 <cfset varName = "dynamicVar5#i#">
 <cfscript> "#varName#" = i;</cfscript>
</cfloop>
<cfset endTime = getTickCount()>
<cfset totalTime = endTime - startTime>
<cfoutput>using the quote and pound method with plain variable for the name (cfscript) = #totalTime#</cfoutput><br>
<cfset uglyList = ListAppend(uglyList, totalTime)>
 
 <br>
 
<cfset niceList = ''>
<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 setVariable() with the concat  method = #totalTime#</cfoutput><br>
<cfset niceList = ListAppend(niceList, totalTime)>
 
<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 niceList = ListAppend(niceList, totalTime)>
 
<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>
<cfset niceList = ListAppend(niceList, totalTime)>
<br><br>
<cfset titleList='concat,plain,plain (cfscript)'>
<table border="1" cellpadding="3"><tr><td></td><td>setVariable(name,  value)</td><td>"var#i#" = i</td><td>%</td></tr>
<cfloop from="1" to="3" index="i">
 <tr align="right"><cfoutput>
  <td>#ListGetAt(titleList, i)#</td>
  <td>#ListGetAt(niceList, i)#</td>
  <td>#ListGetAt(uglyList, i)#</td>
  <cfset pcnt = NumberFormat((ListGetAt(niceList, i) / ListGetAt(uglyList, i) - 1) * 100, "___.__")>
  <td>#pcnt# %</td>
  </cfoutput>
 </tr>
</cfloop>
</table>
 
----- Original Message -----
Sent: Wednesday, February 20, 2002 6:05 PM
Subject: RE: Settings vars with an index loop

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

 

Reply via email to