I develop using ColdFusion and wanted to know what is the best strategy to loop over large query result set. Is there any performance difference between using cfloop and cfoutput? If not, is there any reason to prefer one over the other?
cfloop vs cfoutput on queries
9.1k Views Asked by Abbadon AtThere are 4 best solutions below

There wouldn't be a performance difference using either method, it depends on your coding style really. If you put a <cfoutput>
at the top and bottom of every page then using <cfloop>
will work great. If you use multiple <cfoutput>
and only place where they are needed that works as well.
I personally put <cfoutput>
only where they are necessary, but I wouldn't say that's more correct than placing them at the top and bottom of the page.

I believe it's all the same as performance, Ben Forta
And the rest is pretty much personal preference as far as how you "like" to work with your loop. Keep in mind you should always scope your variables, but inside a cfoutput loop that would be especially important since the query fields "could" be referenced without referring to their scope.
one reason you may prefer the cfloop approach would be if you needed to "escape" cfoutput during your loop for any reason. I have run into that several times, so I generally prefer cfloop.

One good reason to use cfloop instead of cfoutput is if you need to loop a query output within another query output cfoutput does not support nested query outputting. You can however get away with it using cfloops. So:
<cfoutput query="test1">
#test1ID#
<cfoutput query="test2">
#test2ID#
</cfoutput>
</cfoutput>
does not work, but if you replace the cfoutputs with cfloops, it will.
As of CF10, with the ability to group cfloops, that's the only remaining functional difference. They both perform the same.
I believe that there used to be. I think this difference has been tackled, the best bet is to do a test for each to test in you specific use case.
There are some notable differences though.
cfoutput
can do grouped loops, whichcfloop
cannot.For
cfoutput
you can specify thestartrow
and themaxrows
(or the count) to paginate your result. Forcfloop
you have to specify theendrow
index instead of the count.Also you cannot use
cfoutput
for a query nested within an existingcfoutput
tag, you will need to end the containingcfoutput
first.