monthNumber (was: Create a folder with today's date...)
monthNumber (was: Create a folder with today's date...)
- Subject: monthNumber (was: Create a folder with today's date...)
- From: Richard Morton <email@hidden>
- Date: Mon, 11 Feb 2002 14:55:11 +1100
has's message of 11/02/02 12:18 AM contained:
Gnarlodious wrote:
on GetMonthNumber()
set theDate to (current date)
copy theDate to b
set the month of b to January
return 1 + (theDate - b + 1314864) div 2629728
end GetMonthNumber
I was poking around looking for the fastest way of
getting a month as integer...
...and found the following to be quickest
overall:
on monthToInteger(theMonth)
if theMonth is January then return 1
[...]
..Not beautiful, but it's faster than the FV method on the first 10
months
(and much faster than the list iteration method).
If you speed tested these 2 handlers as posted, you're comparing ice
cream to custard. ;-} GetMonthNumber() includes a call to 'current
date', whereas your handler gets the month already supplied.
Whatever you did, I get significantly different results.
I think someone also came up with a simplified FV method a while back -
I'd
be interested in comparing that for speed if anyone has it.
Given that the speed of yours is proportional to the time of year, I
tested it for each month and averaged it. This suggests that
French Vanilla is still faster, though not dramatically.
My current version of it uses the mod suggested by someone (I know I have
it written down somewhere...) here last year. I don't think it makes
much difference to the speed, but it's slightly smaller:
on monthNum from dateObj
copy dateObj to dateTemp
set month of dateTemp to January
return (1 + (dateObj - dateTemp) div 2.5E+6)
end monthNum
The definition of a session in the results below is 10 * 10 * 500
iterations on a G4/400 running OS9.1/AS1.6. The weather was fine and
clear, with a cool southwesterly running about 12 knots, err, anyway...
monthNum from dateObj
--> sessionAvg:0.0498, sessionBest:0.0466, sessionWorst:0.0656 (Jan)
--> sessionAvg:0.0493, sessionBest:0.0466, sessionWorst:0.061 (Dec)
I added a line to your handler to make it equivalent to 'monthNum':
on monthToInteger(theDate)
set theMonth to (month of theDate)
--> sessionAvg:0.0236, sessionBest:0.021, sessionWorst:0.0459 (Jan)
--> sessionAvg:0.0557, sessionBest:0.0522, sessionWorst:0.0683 (Jun)
--> sessionAvg:0.0899, sessionBest:0.0863, sessionWorst:0.1012 (Dec)
--> average for year - 0.0575
--> all in one if statement: June - 0.0522
Putting it into 1 if statement is faster, as I expected, but not by much.
It nearly doubles the line count too. There is an article at AppleScript
This Week which discusses fast ways of getting date strings:
http://www.macadillo.com/ATW/shortdate.html
NG also has (and may have posted somewhere) an excellent date handler
which I call 1/2/3 - an ingenious method for returning date strings in
the
order the user has set in his/her Date & Time CP. I recommend you check
it out if you haven't already.
Cheers,
Richard Morton
-- Great Lies of the Music Business: "I practise 6 hours every day"
_______________________________________________
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.