• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Offset vs. Repeat loops
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: Offset vs. Repeat loops
      • From: Emmanuel <email@hidden>
    • RA and Network Setup Scripting
      • From: Mirko Gude <email@hidden>
References: 
 >Offset vs. Repeat loops (From: Greg Strange <email@hidden>)

  • Prev by Date: Re: how to script resizing in Graphic Converter (Use QT)
  • Next by Date: RA and Network Setup Scripting
  • Previous by thread: Re: Offset vs. Repeat loops
  • Next by thread: RA and Network Setup Scripting
  • Index(es):
    • Date
    • Thread