Rob Rohan wrote:
> Ok, so in Java using a String can cost a lot when you have to append
> over and over (because I think it makes a new String object for each
> iteration) - to fix this you're supposed to use a string buffer. So I
> decided to try using a string buffer in MX to see if I could get a bit
> of a performance gain... check it out
Using an array instead of a string gives a higher performance boost,
even when using plain CFML. The array version below runs about 10 times
faster as the Java version with a string (although after checking they
were of identical length I didn't check whether the strings were identical:
<cfset highnumber = 65536>
<cfset start = GetTickCount()>
<cfscript>
sb_filler = createObject("java","java.lang.StringBuffer");
for(x=0; x lte highnumber; x=x+1){
sb_filler.append(chr(x));
}
</cfscript>
<cfoutput>
<h2>Java: #GetTickCount() - start#</h2>
</cfoutput>
<cfset start = GetTickCount()>
<cfscript>
tempArray = ArrayNew(1);
for(x=0; x lte highnumber; x=x+1){
ArrayAppend(tempArray,chr(x));
}
s_filler = ArrayToList(tempArray,"");
</cfscript>
<cfoutput>
<h2>Array: #GetTickCount() - start#</h2>
#Compare(sb_filler.toString(), s_filler)#
</cfoutput>
More examples of the speed difference between strings and arrays are in
the archives.
Jochem
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Archives: http://www.houseoffusion.com/cf_lists/index.cfm?forumid=4
Subscription:
http://www.houseoffusion.com/cf_lists/index.cfm?method=subscribe&forumid=4
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Your ad could be here. Monies from ads go to support these lists and provide more
resources for the community. http://www.fusionauthority.com/ads.cfm