An observation
Bjoernke von Gierke
bvg at mac.com
Sun Sep 1 08:41:01 EDT 2002
I was using Runrev to format a list which I copied from my browser. As Mozilla copied the List as text, and neither tab nor return delimeted it, I had to find another way to read it. Instead of tabs the text had fortunately multiple spaces, so I could use that as basis, and then count the items until a return had to show up.
I first used multiple "for each chunktype" loops. Then I remembered the "replace chunk with chunk", and used that in a new version. afterwards i compared speed, and found out, that the "replace" command was almost twice as fast!
That will probably not speed up many scripts, but I think it is good to know what command is faster/the fastest for a certain task (especially as there are that many diffrent things that do the same!), so I tought maybe others want to know this too...
Below are the two scripts I used for the speed comparision. I striped the part which included the returns, as it was the same in both scripts (it didn't change the speed compared to each other tough). I repeat the "replace" 10 times, to get rid of all aditional spaces. Below these two scripts is the script which I used to compare the time they each need.
on MouseUp
put field "Input" into theInput
repeat for each char theChar in theInput
if theChar = oldChar and theChar = space then
add one to spacecount
else
if spaceCount <> 0 then
put tab after theResult
put 0 into spaceCount
end if
put theChar after theResult
end if
put theChar into oldChar
end repeat
put word 1 to -1 of theResult into field "Output"
end MouseUp
on MouseUp
put field "Input" into theInput
repeat for 10 times
replace " " with " " in theInput
end repeat
replace " " with tab in theInput
put theInput into field "Output"
end MouseUp
on mouseUp
repeat for 200 times
put the Ticks into Ticki
send mouseUp to button (field "Name")
put the Ticks - Ticki & "," after myresult
end repeat
put sum(myresult)
end mouseUp
More information about the use-livecode
mailing list