• 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: More speed tests in offset handlers
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: More speed tests in offset handlers


  • Subject: Re: More speed tests in offset handlers
  • From: Arthur J Knapp <email@hidden>
  • Date: Tue, 09 Oct 2001 10:53:08 -0400

> Subject: Re: More speed tests in offset handlers
> Date: Tue, 9 Oct 2001 02:45:35 +0100
> From: Nigel Garvey <email@hidden>

> Greg Back wrote on Mon, 08 Oct 2001 16:27:43 -0400:
>> I didn't get these in time to do a speed test. Have to go do some other
>> stuff soon. Anyone care to test for me??

> Well...

>> on GetIndex(a, i)
>> if a contains i then repeat with x from 1 to a's length
>> if a's item x = i then return x
>> end repeat
>> return 0

> A more compact version of your own handler, probably about the same speed.

But it looks really cool... ;-)


>> -- Binary-Search, split the list into smaller parts, makes great use
>> -- of the "contains" operator.

If I had seen Nigel's posting first, I wouldn't have posted this.

>> to BinarySearch(a, i, l, r)

When I first threw this together, my thought had been that it was going
to be recursive. Otherwise, I wouldn't have included the left and right
boundry parameters.

>> if a's items l thru r contains i then
>> repeat until l = r
>> set m to (r + l) div 2
>> if a's items l thru m contains i then
>> set r to m
>> else
>> set l to m + 1
>> end if
>> end repeat
>> else
>> return 0

> Very similar to the binary search I posted, but offering the ability to
> specify a search range within the list and using a different exit
> criterion. It seems to be mostly faster than mine. (Gasp!)

I know how hard it was to admit that... ;-)

>> property offsetSentinal : ASCII character 1 -- speed up repeated calls
>>
>> on offsetOf(a, s) -- case-sensitive
>> set oldDelim to text item delimiters
>> set text item delimiters to offsetSentinal
>> set a to offsetSentinal & a & offsetSentinal
>> set x to offset of (offsetSentinal & s & offsetSentinal) in a
>> if (x is not 0) then
>> set x to count of text items in (a's text 1 thru x)
>> set x to x - 1
>> end if
>> set text item delimiters to oldDelim
>> return x

> The fastest method known to mankind, as all the looping is done by the
> underlying low-level code rather than by the script itself. As Arthur's
> noted, it only works with lists whose items are all coercible to string,
> and its use of text item delimiters and 'offset' makes it case-sensitive.
> Since it coerces the whole list to a single string, it's unable to
> distinguish between non-string items and strings. Thus:
>
> offsetOf({2 + 2 = 4, "aardvark", "true"}, "true")
> --> 1

Only someone really mean would have pointed that out... ;-)

> I won't mention the external property on which this handler depends as
> Arthur's a good fr... Oops!

No one likes my handler-property-helpers, WHY!!!

;-)


Arthur J. Knapp
http://www.stellarvisions.com
mailto:email@hidden

Hey, check out:
http://www.zavatone.com/


  • Prev by Date: RE: Scripting Airport?
  • Next by Date: EU as text
  • Previous by thread: Re: More speed tests in offset handlers
  • Next by thread: Stay Open Script Won't Quit
  • Index(es):
    • Date
    • Thread