Poor performance of string functions

hi,

the following code

Dim s As String

s=“”

For i=1 To 10000

s=s+“anything”

Next i

Print Time()

For j=1 To 2500

k= Len(s)

Next j

Print Time()

performs with LN 5.0.X more than 10 times faster as with LN 6.0.X

Has anybody a explanation for this?

We use a LotusScript StringTokenizer function which performs very bad with large strings if run with LN 6.0.X

Thank you

Hueseyin

Subject: poor performance of string functions

my problem is not the string concatenations (its only for reproducing). my problem is the

k=len(s)

function, which is much slower in R6 as with R5.

I read a RichTextField with 2500 lines and step through them. i can use the new NotesRichTextNavigator class in R6 to do it (its fast), but not everybody has a R6 client.

Subject: Hmm…

not sure why there is a performance drop between R5.x and R6.x, but from a general point of view, string concatenations (especially the repeated appends in your example code) are always relatively slow, because internally in most BASIC-type languages the strings get temporaily duplicated, memory allocated, freed, etc. The general solution to this for fast string performance is to write a custom function or class which joins the strings together not by concatenation but by array joins (array operations are much faster than string operations).

If you search on google for “Fast string operations”, you’ll find tons of related information.

Thomas - IBM

Subject: Our tests

We tested pushing out a big report using string concatenation versus writing each line. We found that by writing each line at the end of a cycle, we improved performance of the report ten-fold.

Subject: Same in Java - Hmm…

… from a general point of view, string concatenations (especially the repeated appends in your example code) are always relatively slow, because internally in most BASIC-type languages the strings get temporaily duplicated, memory allocated, freed, etc. <<<

This is also true in Java, but see this Java best practices post for a workaround:

Subject: RE: Hmm…

So why doesn’t IBM use those faster solutions in it’s own standard operations?:wink:

SCNR,

Oliver Regelmann