Re: Determining item number matching "x" in a list
Re: Determining item number matching "x" in a list
- Subject: Re: Determining item number matching "x" in a list
- From: Nigel Garvey <email@hidden>
- Date: Sat, 15 Mar 2003 02:51:14 +0000
Emmanuel wrote on Fri, 14 Mar 2003 18:50:09 +0100:
>
At 11:47 AM -0500 14/03/03, Steve Cunningham wrote:
>
>Emmanuel wrote
>
>
>
>>NG's "getindex" requires 170 +or- 25 microseconds
>
> >My "IndexOfItem" requires 809 +or- 37 microseconds
>
>
>
>I can't reproduce these results :-( I don't mean absolutely, but
>
>relatively.
>
>[...]
>
>Seems like while our absolute times will certainly be different, the
>
>relative rankings should be the same.
>
>
Sure. Unfortunately I trashed the testing program. I'll pseudo-write it
>
here:
>
>
(theList should contain 20 short strings)
Well. After all the discussion, I just had to compare the two myself on
my own Pismo 400MHz. Necessarily, this was in 9.2.2 in order to use 'the
ticks'. (The handlers themselves aren't shown shown in this test code):
set strList to {"Stratford-upon-Avon", "Shottery", "Wellesbourne",
"Barford", ,
"Snitterfield", "Wolverton", "Hampton Lucy", "Charlecote", ,
"Kineton", "Ettington", "Halford", "Bishops Itchington", ,
"Wilmcote", "Aston Cantlow", "Upper Billesley", "Hatton Rock", ,
"Pathlow", "Bearley", "Warwick", "Royal Leamington Spa"}
set lotsa to 100
set l1 to {}
repeat with i from 1 to 20 -- 20 items
set t to the ticks
repeat lotsa times -- get each index 100 times
getindex of (item i of strList) into strList
end repeat
set the end of l1 to (the ticks) - t
end repeat
set l2 to {}
repeat with i from 1 to 20
set t to the ticks
repeat lotsa times
IndexOfItem(item i of strList, strList)
end repeat
set the end of l2 to (the ticks) - t
end repeat
{Binary:l1, TIDs:l2}
--> {Binary:{5, 6, 10, 13, 17, 18, 21, 18, 21, 25, 24, 17, 21, 23, 27,
26, 25, 27, 30, 29}, TIDs:{11, 11, 11, 11, 12, 11, 11, 11, 12, 11, 11,
11, 13, 11, 11, 11, 11, 12, 11, 11}}
As I would have expected, mine takes longer the further up-list the
item's located, with variations due to random fluctuations and the
distribution of favoured positions in the list. Emmanuel's effort is
fairly constant in speed and soon becomes the faster option.
That said, the TIDs method is - as I mentioned yesterday - only good for
text and is case-sensitive. My binary search, as it stands, is
handicapped speedwise by being case-insensitive. The strings have to be
converted to one case by the underlying code before they're compared. If
the binary search is made case-sensitive too, by enclosing the call in a
'considering case' block, the case conversions don't take place and the
playing field gets levelled a bit:
--> {Binary:{4, 6, 7, 10, 11, 11, 13, 10, 12, 14, 13, 10, 11, 12, 14,
14, 12, 14, 16, 14}, TIDs:{11, 11, 11, 12, 11, 11, 11, 12, 10, 12, 11,
11, 11, 11, 11, 11, 12, 11, 11, 11}}
NG
_______________________________________________
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.