RB strings are not mutable...

When you call " s = s + str(i) " a new string is created in memory, the value of the old string plus the new string are added together an placed in the new string, and then the old string is taken out of memory.

Each iteration of this loop will therefore be a little longer than the last, as the string slowly winds it's way up to 50,000 characters long.

Array's are much faster than strings for appends, but I defy you to do an instr or countfields operation on one of your fast strings....

Different horses for different courses Kem....

- Tom

On 12/02/2007, at 4:17 PM, Kem Tekinay wrote:

I know this has probably been done to death, but I wanted emphasize how slow
strings are in REALbasic for appends. Consider this code, for example:

    for i as integer = 1 to 50000
      s = s + str( i )
    next i

This takes 17 seconds to run in a compiled app on a PowerMac G5 dual-2.5
GHz.

Meanwhile, I took about an hour to create a custom class called FastString
that uses an array to hold the parts of the string. By defining the
Operator_Add and Operator_Convert methods, I can change s above from a
string to a FastString, and the exact same code takes 0.1 seconds! If I rewrite the code to use a method within FastString, it takes half that:

    for i as integer = 1 to 50000
      s.Append( str( i ) )
    next i

OK, so part of this is bragging, but the more serious question is, if I could do this in an hour, why can't RB use the same behavior in its native
strings?

______________________________________________________________________ ____ Kem Tekinay (212) 201-1465 MacTechnologies Consulting Fax (914) 242-7294 http://www.mactechnologies.com Pager (917) 491-5546

To join the MacTechnologies Consulting mailing list, send an e- mail to:
           [EMAIL PROTECTED]








_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>

Reply via email to