Gert Franz wrote:
>
> just change "some text" to something about 10 times larger and change
> the 500 to maybe 5000 and then you'll find out how fast string buffer is
> in comparison to CFMX strings...
Neat. I just did 2,000,000 string appends of a 26 character string,
resetting the string to empty every 1000 iterations, for a total string
length of 52 megabytes (mebibytes?)
Anyway, the old fashioned CFML took 89 seconds. The java string buffer
method took only 28 seconds
Here's the code:
<cfset a = "">
<cfset starttime = now()>
<cfset cnt = 0>
<cfloop index="i" from="1" to="2000000">
<cfset a = a & "This is some crazy stuff. ">
<cfset cnt = cnt + 26>
<cfif i mod 1000 is 0>
<!--- write to file and reset string to empty --->
<cfset a = "">
</cfif>
</cfloop>
<cfoutput><p>Done with #cnt# bytes in
#abs(dateDiff('s',Now(),starttime))# seconds.</p></cfoutput>
<cfset a = createObject("java","java.lang.StringBuffer")>
<cfset starttime = now()>
<cfset cnt = 0>
<cfloop index="i" from="1" to="2000000">
<cfset a.append("This is some crazy stuff. ")>
<cfset cnt = cnt + 26>
<cfif i mod 10000 is 0>
<!--- write to file and reset string to empty --->
<cfset a = createObject("java","java.lang.StringBuffer")>
</cfif>
</cfloop>
<cfoutput><p>Done with #cnt# bytes in
#abs(dateDiff('s',Now(),starttime))# seconds.</p></cfoutput>
(I reset the string buffer every 1000 iterations because in the real
world, I'd be writing out the file every so often rather than writing
one giant file)
Rick
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Introducing the Fusion Authority Quarterly Update. 80 pages of hard-hitting,
up-to-date ColdFusion information by your peers, delivered to your door four
times a year.
http://www.fusionauthority.com/quarterly
Archive:
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:250294
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe:
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4