Re: Offset vs. Repeat loops
Re: Offset vs. Repeat loops
- Subject: Re: Offset vs. Repeat loops
- From: Andy Wylie <email@hidden>
- Date: Sat, 07 Jul 2001 19:35:58 +1200
on 7/7/01 11:47 am, Greg Strange at email@hidden wrote:
>
So,
>
>
Michelle posted an excellent handler for changing strings form upper to
>
lowercase and vice versa. I thought it good but I thought that getting the
>
offset of one in the other string faster given that you don't have to loop
>
through every character. The difference was amazing. Michelle's mod
>
finished 1000 iterations in 518 ticks (on average through five overall
>
runs). Mine posted below did 1000 iterations in 2321 ticks (on average
>
through five overall runs)!
>
>
Why is offset so much slower than repeat loops? That seems
>
counterintuitive. (Mind the wraps!)
>
>
global lowercasestring, uppercasestring, outString
>
set outString to ""
>
set lowercasestring to "abcdefghijklmnopqrstuvwxyz"
>
set uppercasestring to "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
>
>
to uppercase(theText)
>
repeat with i in theText
>
try
>
set myOffset to the offset of i in lowercasestring
>
set outString to outString & character myOffset of
>
uppercasestring
>
on error
>
set outString to outString & i
>
end try
>
end repeat
>
return outString
>
end uppercase
>
>
>
to lowercase(theText)
>
repeat with i in theText
>
try
>
set myOffset to the offset of i in uppercasestring
>
set outString to outString & character myOffset of
>
lowercasestring
>
on error
>
set outString to outString & i
>
end try
>
end repeat
>
return outString
>
end lowercase
>
_______________________________________________
Greg, replacing...
--------
set myOffset to the offset of i in lowercasestring
set outString to outString & character myOffset of
uppercasestring
--------
with...
--------
set outString to outString & uppercasestring's character (offset of i in
lowercasestring)
--------
is 10 times faster, using the list example I posted earlier is only slightly
faster, Satimage OSAX is 400 times faster!
_____________________________ Andy