On 12/8/06 4:58 PM, Charles Yeomans at [EMAIL PROTECTED] wrote:
> Perhaps my English is not so clear; let's try again.
>
> Fast string routines exist right now in REALbasic.
Consider this code. Of the two loops, which would you expect to be faster?
const kReps = 1000000
dim t1, t2 as double
t1 = microseconds
for i as integer = 1 to kReps
dim s as string = "something"
s = s + " "
s = s + "else"
next
t1 = microseconds - t1
t2 = microseconds
for i as integer = 1 to kReps
static output( 2 ) as string
output = array( "something", " ", "else" )
dim s as string = join( output, "" )
next
t2 = microseconds - t2
t1 = t1 / 1000000
t2 = t2 / 1000000
dim tally as string = format( t1, "#,0.000" ) + chr( 13 ) + format( t2,
"#,0.000" )
MsgBox tally
If you said the second, you would be wrong. The first ran almost twice as
fast as the second. Even replacing the second loop thusly to avoid the
creation of the array each time does not make it faster than the first:
t2 = microseconds
for i as integer = 1 to kReps
static output( 2 ) as string
output( 0 ) = "something"
output( 1 ) = " "
output( 2 ) = "else"
dim s as string = join( output, "" )
next
t2 = microseconds - t2
Of course, this is "cheating" a bit because it assumes you know in advance
how many strings you will be joining.
__________________________________________________________________________
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 of this list here:
<http://support.realsoftware.com/listarchives/lists.html>