Please note, new blog at http://www.acheron.org/darryl/

CFSAVECONTENT vs. concatenation

I've been mucking around with generating CSV files over the last couple of days, and testing the difference between CFSAVECONTENT and good old concatenation. A lot of people know this already, but using CFSAVECONTENT like this: <cfsavecontent variable="local.sData"> <cfoutput query="local.qData">#chr(34)##local.qData.col1##chr(34)#, #chr(34)##local.qData.col2##chr(34)##chr(13)##chr(10)# </cfoutput> </cfsavecontent> is a LOT quicker than: <cfset local.sOutput = ""> <cfoutput query="local.qData"> <cfset local.sOutput = local.sOutput & chr(34) & local.qData.col1 & chr(34)> <cfset local.sOutput = local.sOutput & chr(34) & local.qData.col2 & chr(34)> <cfset local.sOutput = local.sOutput & chr(34) & local.qData.col3 & chr(34)> <cfset local.sOutput = local.sOutput & chr(13) & chr(10)> </cfoutput> In this example, concatenating the string together can take up to 1 second. Using CFSAVECONTENT, the same string can take only 90 milliseconds to create (even with heaps more data).

» Post a Comment

Trackbacks:

» Create a Link