Good call, then you avoid the overhead of the object creation; however,
there are other things you can do with a string buffer that you can't do
with a simple array.

I dig your example.

Rob

http://treebeard.sourceforge.net
http://ruinworld.sourceforge.net
Scientia Est Potentia

-----Original Message-----
From: Jochem van Dieten [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, November 27, 2002 2:10 PM
To: CF-Talk
Subject: Re: Check this out - MX performance enhancer


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
Structure your ColdFusion code with Fusebox. Get the official book at 
http://www.fusionauthority.com/bkinfo.cfm

Reply via email to