[Helma-user] Small patch for loop macro

tobias.schaefer at orf.at tobias.schaefer at orf.at
Fri May 11 10:46:16 CEST 2007


> If you just have one string to output, it doesn't make much of a
> difference, since the Helma Skin class will just do the res.write()
> for you. If, on the other hand, your macro output is composed of many
> small pieces, it's better to directly use res.write(), since
> composing a string with multiple + concatenations adds a lot of
> memory overhead (each + operation results in the whole string being
> reallocated in memory).      

which is, btw., not true anymore in browsers (esp. firefox). i once benchmarked the various methods (see below) and found that only helma/rhino behaves pretty badly when concatenating strings via the "+" operator.

the methods i checked:

 * String assignment: str = str + "foo"
 * String.concat: String.concat(str, "foo") // if available
 * Array assignment: arr[arr.length] = str
 * Array.push: arr.push(str)

here's a typical result creating strings with 50.000 chars as an example (the first values represent the duration in milliseconds, the string lengths appear in brackets):

Browser (IE)
String assignment: 1031 (50000)
Array assignment: 406 (50000)
Array.push: 547 (50000)

Server
String assignment: 6256 (50000)
Array assignment: 112 (50000)
Array.push: 133 (50000)

--

Browser (Moz)
String assignment: 47 (50000)
String.concat: 797 (50000)
Array assignment: 172 (50000)
Array.push: 203 (50000)

Server
String assignment: 6388 (50000)
Array assignment: 337 (50000)
Array.push: 249 (50000)


(i attached the source code of the benchmark test to this message -- hope it gets through our firewall :)

i am still wonderung what could be the reason that the string concatenation operator performs so differently in helma/rhino?

ciao,
tobi
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: str_benchmark.txt
Url: http://helma.org/pipermail/helma-user/attachments/20070511/120a7f8f/attachment.txt 


More information about the Helma-user mailing list