I tried Charles code below in my Powerbook G4 1.33 GH, 1GB ram and it took 131 seconds. By substituting val( line ) <> 0 for isNumeric ( line ) I got it to 72 seconds, about 60% faster.

I don't have perl installed so I didn't test that script.

gary hayenga


On Dec 8, 2006, at 3:14 PM, realbasic-nug- [EMAIL PROTECTED] wrote:


Message: 4
Subject: Re: The perl challenge
From: Charles Yeomans <[EMAIL PROTECTED]>
Date: Fri, 8 Dec 2006 13:58:59 -0500


On Dec 8, 2006, at 12:09 PM, Alberto Paderno wrote:

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:realbasic-nug->[EMAIL PROTECTED] On Behalf of
Kem
Tekinay


Imagine my surprise when it took RB a minute to do what perl did
in 15
seconds. I'm not surprised that perl is faster, only HOW much
faster it is.
My argument was going to be, "see, difference wasn't that much,
and RB is
much easier to read," but these results make it no contest.

So my question is: Why is RB so much slower? What is it doing
that's making
the difference? And could I do something to close the gap?

REALbasic is really slow on handling functions because it continues to
create new instances of strings all the times you make operations
on them.
If you want to make your code faster, you could use the ElfData
plug-in
which has some classes to handle strings faster. You can find it on
http://www.elfdata.com/plugin/: it runs on all platforms, and it's
free to
use if you just use it to make some code test, or to make some GPL
licensed
code.
Read well how to use it correctly, and to avoid conversion from
ElfData to
string which would be worst than to use just strings.

I hope that can help you.
--

I wouldn't expect it to because of the nature of the string
concatenation in this code.  Below is a version that replaces the
string concatenation with something faster.  I also changed the while
loop to a do loop and replaced the evil Close methods.  And I moved
the declaration of the variable 'line' inside the loop.

The next thing I'd check is to see how fast IsNumeric is.

Charles Yeomans

-------------------------------

   #pragma BackgroundTasks false
   #pragma BoundsChecking false

   dim fIn, fOut as FolderItem
   dim t as Double = microseconds

   fIn = DesktopFolder.Child( "test.txt" )
   fOut = DesktopFolder.Child( "output.txt" )

   dim tIn as TextInputStream = fIn.OpenAsTextFile
   dim tOut as TextOutputStream = fOut.CreateTextFile


   do until tIn.EOF
     dim line as string =  tIn.ReadLine
     if IsNumeric( line ) then
       static output(1) as String = Array("case ", "")
       output(1) = line
       tOut.WriteLine Join(output, "")
     else
       static output(2) as String = Array("r = """, "", """")
       output(1) = ReplaceAllB( line, """", """""" )
       tOut.WriteLine(Join(output, "")
     end if
   loop

   tIn = nil
   tOut = nil

   t = microseconds - t
   t = t / 1000000

   MsgBox( format( t, "#,0.000" ) + " seconds" )




_______________________________________________
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