Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Click here to return to the 'a strange non-optimization comment' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
a strange non-optimization comment
Authored by: Krioni on Oct 25, '09 06:33:06PM

NOTE: This comment (below) is _NOT_ something you should use to modify the original hint.

I took a look at how you could ask Address Book to give you a list of people who have phones (using the AppleScript command 'whose'), rather than having to loop over every contact. Unfortunately (but not really that surprising), Address Book is MUCH slower at doing that filtering up front than it is at looping over each person separately.

So, the code shown below is for informational purposes only - it would much the script much slower:

set phoneContacts to every person whose (value of first phone of it) is not missing value

Now, this takes about 20 seconds to run on my Address Book database of about 1000 contacts. When I tested the original code, the loop-over-all-contacts takes about 1 second.

I thought at first that it would be faster to just get the list of people you actually want, but, as is often the case in AppleScript, the 'whose' command fails amazingly here. I originally was going to post this alternative code without testing, but based on past experiences, I thought it would be good to know how well the original code ran. The result? Original code in the hint is 20 times faster. Wow.

Aside: A similarly slow command that would get only people who have no phones:

set phoneContacts to every person whose (value of first phone of it) is missing value

AppleScript is a strange beast - this is by far not the strangest thing I've seen over the years.


[ Reply to This | # ]