[thelist] CF Arrays vs. List Tip

Joshua Olson joshua at alphashop.net
Sun Sep 16 18:11:39 CDT 2001

<tip type="ColdFusion" author="Joshua Olson">
ColdFusion Array handling is *much* faster than list functions.  If you have
an loop that iterates through a list and uses ListGetAt in every loop, you
may find a significant speed increase by creating an array before the loop
ListToArray and using indexes instead.  The longer the lists, the more
profound the disparity becomes.


Assume you have two long lists of the same length and you want to display
elements from both lists side by side.

slow method

<cfloop from="1" to="#ListLen(longList)#" index="i">
  <cfset text1 = ListGetAt(long, i)>
  <cfset text2 = ListGetAt(complementaryList, i)>
  #text1# - #text2#<br>

faster method

<cfset longArray = ListToArray(longList)>
<cfset complementaryArray = ListToArray(complementaryList)>

<cfloop index="i" from="1" to="#ArrayLen(longArray)#">
  #longArray[i]# - #complementaryArray[i]#<br>


More information about the thelist mailing list