• 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: "mylist" vs "a reference to" - speed difference
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: "mylist" vs "a reference to" - speed difference


  • Subject: Re: "mylist" vs "a reference to" - speed difference
  • From: email@hidden (Michael Sullivan)
  • Date: Fri, 26 Apr 2002 12:15:23 -0400
  • Organization: Society for the Incurably Pompous

Arthur J. Knapp writes:

> > Subject: Re: "mylist" vs "a reference to" - speed difference
> > Date: Fri, 26 Apr 2002 02:13:34 +0100
> > From: Nigel Garvey <email@hidden>
>
> > Your line 'set isalist to my thelist' just sets 'isalist' to the same as
> > 'thelist'. The speed gain comes from accessing items in the list while
> > refering to the list with an expression rather than a simple variable
> > name. It's only worthwhile with very large lists and/or with a very large
> > number of operations on the items.
>
> I just wanted to point out that Nigel here was the guy who discovered
> that the "my" technique was actually faster than the "Serge" technique of
> directly calling a script object's properties and methods, (found by Serge
> Belleudy-d'Espinose, of course).
>
> repeat ( many ) times

> -- In order of average best iterative speed:
> --
> get/set variableList's item x -- normal item access
> get/set aReferenceToList's item x -- explicit saved reference
> get/set myScript's propertyList's item x -- "Serge" access
> get/set my propertyList's item x -- "Nigel" access
>

But the last 2 are so close that the difference doesn't really matter
for most purposes. I don't think "my" is actually any faster. Maybe it
depends on what you're doing with the list.

I just did a test run where the object access took one fewer tick. The
second (explicit reference) seems to be slower by a constant factor of
around 3.5. It's only likely to make a difference with a lot of reps.

Here's my test:

set len to 1000
set reps to 20

set t0 to the ticks

set theList to {}
repeat with i from 1 to len
set end of my theList to i
end repeat

to initScript(aList)
script o
property theList : aList
end script
return o
end initScript

set o to initScript(theList)
set listRef to a reference to theList

set t1 to the ticks

repeat reps times
repeat with i from 1 to len
set k to item i of my theList
end repeat
end repeat

set t2 to the ticks

repeat reps times
repeat with i from 1 to len
set k to item i of o's theList
end repeat
end repeat

set t3 to the ticks

repeat reps times
repeat with i from 1 to len
set k to item i of listRef
end repeat
end repeat

set t4 to the ticks

{t1 - t0, t2 - t1, t3 - t2, t4 - t3}

--> {2, 63, 63, 209}

An interesting note is that *building* the list originally, takes
significantly less time than traversing it by any of these methods. But
when I test with a list of 20,000, it takes *longer* than traversing it
by the faster methods. The crossover point is around 5000 items.

I'm guessing that building is actually faster in general, but as the
list gets longer, there needs to be more memoy management that slows
things down.


Michael

--
Michael Sullivan
Business Card Express of CT Thermographers to the Trade
Cheshire, CT email@hidden
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: "mylist" vs "a reference to" - speed difference
      • From: Paul Berkowitz <email@hidden>
References: 
 >Re: "mylist" vs "a reference to" - speed difference (From: Arthur J Knapp <email@hidden>)

  • Prev by Date: Re: Referencing a folder with "~" in the name
  • Next by Date: Re: Owner/User Name in OSX
  • Previous by thread: Re: "mylist" vs "a reference to" - speed difference
  • Next by thread: Re: "mylist" vs "a reference to" - speed difference
  • Index(es):
    • Date
    • Thread