Thursday, August 14, 2008

ColdFusion Looping Techniques

For those of you that may not be familiar with ColdFusion, it has a lot of different ways to loop over a collection of data. There is, of course, the query loop:


<cfloop query="MyQuery">

There are other looping methods for other data collections like lists, arrays, and structures. When it comes to arrays versus lists, the mantra has always been that arrays are always more efficient than arrays. Lists, however, are deeply ingrained in the programming habits of most ColdFusion developers, which is undoubtedly helped by the presence of functions like ValueList.

I recently heard about a comparison of the performance of the various looping techniques that was posted on a blog by Brian and Eric. It's a well written article, and I recommend reading the whole thing. However, the important point that I took away was that looping over an array was only marginally better than looping over a list. All other looping techniques were significantly less efficient.