ColdFusion, AJAX and web...
<cftimer type="inline" label="Regular concentation">
<cfscript>
iNrTimesToLoop = url.nr;
sStringToConcat = "The quick brown fox jumped over the fence: ";
sString = "";
for (x=1; x LTE iNrTimesToLoop; x=x+1)
{
sString = sString & sStringToConcat & x;
}
</cfscript>
</cftimer>
ArrayAppend
<cftimer type="inline" label="ArrayAppend">
<cfscript>
iNrTimesToLoop = url.nr;
sStringToConcat = "The quick brown fox jumped over the fence: ";
aString = ArrayNew(1);
for (x=1; x LTE iNrTimesToLoop; x=x+1)
{
temp = ArrayAppend(aString, sStringToConcat & x);
}
// Convert back into a string
sString = ArrayToList(aString, "#chr(13)##chr(10)#");
</cfscript>
</cftimer>
I put together a similar test for Flash.. diferent results entirely of course..
http://oddhammer.com/actionscriptperformance/set3/index.html
(test #15)
<cftimer type="inline" label="ListAppend">
<cfscript>
iNrTimesToLoop = url.nr;
sStringToConcat = "The quick brown fox jumped over the fence: ";
aString = "";
for (x=1; x LTE iNrTimesToLoop; x=x+1)
{
temp = ListAppend(aString, sStringToConcat & x);
}
</cfscript>
</cftimer>
We achieve better times as we avoided using 2 function calls
- ArrayNew(1)
- ArraytoList()
try url.nr > 20000 to see some appreciable diff between the 2 methods