With all due respect, your code actually measures the penalty for dimming
your variables inside the loop.  Remove the dim statements to the top of the
program, and the second loop (join) becomes the faster option.  You also pay
a penalty for using the array("something", " ", "else") line, over setting
the array elements individually.  This speeds up the second loop even
further.

Tim


> -----Original Message-----
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] Behalf Of
> Charles Yeomans
> Sent: Friday, December 08, 2006 3:14 PM
> To: REALbasic NUG
> Subject: Re: The perl challenge
>
>
>
> On Dec 8, 2006, at 5:28 PM, Kem Tekinay wrote:
>
> > 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:
>
> Okay.  Were you intending this to be a counterexample to my claim?
>
> Charles Yeomans
> _______________________________________________
> 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>
>
> --
> No virus found in this incoming message.
> Checked by AVG Free Edition.
> Version: 7.5.432 / Virus Database: 268.15.15/580 - Release Date:
> 12/8/2006 12:53 PM
>
--
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.5.432 / Virus Database: 268.15.15/580 - Release Date: 12/8/2006
12:53 PM

_______________________________________________
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>

Reply via email to