Re: Month as Integer (or he's ranting again)
Re: Month as Integer (or he's ranting again)
- Subject: Re: Month as Integer (or he's ranting again)
- From: Sun Real <email@hidden>
- Date: Sun, 3 Dec 2000 09:47:48 +1100
On Fri, 1 Dec 2000 01:25:21 -0800, Richard 23 <email@hidden>
wrote:
>
Sun Real said:
>
>
>The months names are constants, not variables. I haven't played with
>
>this but I (a) don't think it could be made to work and (b) wouldn't
>
>recommend trying to use constants as record labels in any case. The
>
>fastest of these methods was posted by Michelle Steiner yesterday.
>
>
Oh, come on! Thinking outside the box is fun!
;-} You're quite right and I've really enjoyed watching you do it.
>
3. The fastest? Do I smell a challenge? Did you benchmark the
>
posted methods? Them's fightin' werds! 8)
You bet! I benchmarked them a while back and posted the results here and
to MacScript. There is also an article I wrote about them at AppleScript
This Week:
http://www.macadillo.com/atw/
There was roughly an order of magnitude difference in speed between the
offset, repeat loop and arithmetical methods (slowest to fastest), tested
on an old 604 machine.
I just tested them again with your offset method, which was somewhat
different to the one I previously benchmarked. Yours is faster, but will
only work under OS8.6 or higher due to the month name to string coercion.
You're not going to be in the race if you're calling 'offset'.
Results are for 10 sessions of 10 * 1000 iterations, on a G4/400 under
OS9.0.4. Times are in seconds but are just for comparative purposes.
Month was December, worst case for the repeat loop method.
-- sessionAvg:2.0461
count words of (text 1 thru (offset of (text 1 thru 3 of ,
(theDate's month as string)) in Month_String) of Month_String)
-- sessionAvg:1.1807
repeat with i from 1 to 12
if theDate's month = item i of monthList then
set mm to i
exit repeat
end if
end repeat
mm
-- sessionAvg:0.0841
copy theDate to b
set month of b to January
copy 1 + ((theDate - b + 1314864) div 2629728) to theMonth
I don't think you're going to beat Emmanuel's arithmetical method. Does
that smell like a challenge? ;-P
Cheers,
Richard Morton
-- Great Lies of the Music Business: "We'll have you back next week"