• 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: Sort items in a list without OSAXen
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Sort items in a list without OSAXen


  • Subject: Re: Sort items in a list without OSAXen
  • From: Paul Skinner <email@hidden>
  • Date: Tue, 04 Sep 2001 23:25:42 -0400

on 9/4/01 6:44 PM, Shane Stanley wrote:

> On 4/9/01 11:57 PM +1000, Arthur J Knapp, email@hidden, wrote:
>
>> A slight speed improvement for larger lists can be obtained by
>> using AppleScript's pattern setting:
>>>> on getsumofhighestthree(UnsortedList)
>>
>>>> -- set a to 0 --the lowest possible value in UnsortedList
>>>> -- set b to a
>>>> -- set c to a
>>
>> set {a, b, c} to {0, 0, 0}
>
> Isn't the latter a mirage? I mean, if I send something like it to an app, it
> still sends three events.
>
> And if I run:
>

Snip! - The Ticks timing code.

For the timing fans in the crowd. This requires the 'precision timing
OSAX'.

--Timer code
set iterations to 10000
set timerReference to install precision timer
repeat iterations times
--Timer code

set a to 0
set b to a
set c to a

--Timer code
end repeat
set timeElapsed to stop precision timer timerReference
set theRate to ((1 div (timeElapsed / iterations)) as text) & "
iterations/second."
set the clipboard to theRate
display dialog theRate
--Timer code


--Timer code
set iterations to 10000
set timerReference to install precision timer
repeat iterations times
--Timer code

set {a, b, c} to {0, 0, 0}

--Timer code
end repeat
set timeElapsed to stop precision timer timerReference
set theRate to ((1 div (timeElapsed / iterations)) as text) & "
iterations/second."
set the clipboard to theRate
display dialog theRate
--Timer code

Here I get 55039 iterations/second vs. 8877 iterations/second.

I was going to suggest that the speed hit comes from copying the values
of a, b, and c to temporary locations in memory while the values get
reassigned. This happens whenever you use pattern assignation.

However, on further testing I found that...

set x to {0, 0, 0}
set {a, b, c} to x

is even slower at 7815 iterations/second. I assume it's not the temporary
assignment of the values but the actual process behind pattern assignment
that's slow. Price you pay for memory efficiency.

--
"Capital letters were always the best way of dealing with things you didn't
have a good answer to." -- Douglas Adams

Paul Skinner


References: 
 >Re: Sort items in a list without OSAXen (From: Shane Stanley <email@hidden>)

  • Prev by Date: Re: Sort items in a list without OSAXen
  • Next by Date: Re: Sort items in a list without OSAXen
  • Previous by thread: Re: Sort items in a list without OSAXen
  • Next by thread: Re: Sort items in a list without OSAXen
  • Index(es):
    • Date
    • Thread