• 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: monthNumber (was: Create a folder with today's date...)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: monthNumber (was: Create a folder with today's date...)


  • Subject: Re: monthNumber (was: Create a folder with today's date...)
  • From: has <email@hidden>
  • Date: Mon, 11 Feb 2002 15:06:22 +0000

Richard Morton wrote:

[FV vs ifThen]
>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.

No, no, was a fair test, one hand tied behind my back, etc. ;)

Here's a fresh comparison, using an if...elseif block as Paul suggested
(=30% faster than my previous version).

======================================================================

on monthToInteger(theMonth)
if theMonth is January then
return 1
else if theMonth is February then
return 2
else if theMonth is March then
return 3
else if theMonth is April then
return 4
else if theMonth is May then
return 5
else if theMonth is June then
return 6
else if theMonth is July then
return 7
else if theMonth is August then
return 8
else if theMonth is September then
return 9
else if theMonth is October then
return 10
else if theMonth is November then
return 11
else if theMonth is December then
return 12
else
error "Invalid value (not a month)."
end if
end monthToInteger

on GetMonthNumber(theDate)
copy theDate to b
set the month of b to January
return 1 + (theDate - b + 1314864) div 2629728
end GetMonthNumber

set r to date "Sunday, December 1, 2002 12:00:00am"

set a to the ticks
repeat 100000 times
monthToInteger(r's month)
end repeat
set b to the ticks
repeat 100000 times
GetMonthNumber(r)
end repeat
set c to the ticks
{b - a, c - b}

--> {150, 373} (January)
--> {329, 380} (December)

======================================================================

Now, it beats FV even in the worst case (December), at least for me. It may
be that other folks' mileage varies according to AS version (I'm on 1.3.7 -
can't speak for other versions).



>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

Aye, seems about the same speed as the last one.


>monthNum from dateObj
>--> sessionAvg:0.0498, sessionBest:0.0466, sessionWorst:0.0656

>> on monthToInteger(theDate)
>--> sessionAvg:0.0236, sessionBest:0.021, sessionWorst:0.0459 (Jan)
>--> sessionAvg:0.0899, sessionBest:0.0863, sessionWorst:0.1012 (Dec)

Mmmm... mileage must definitely vary. Maybe it's that hunky G4 of yours, or
perhaps AS1.6... who knows.


>Putting it into 1 if statement is faster, as I expected, but not by much.
>It nearly doubles the line count too.

Hey, looks aren't everything you know. Personality goes a long way too. ;)


>There is an article at AppleScript
>This Week which discusses fast ways of getting date strings:
>
>http://www.macadillo.com/ATW/shortdate.html

Neat, I'll have a look.


>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.

I might have seen this, I can't recall. Interesting idea, though as folks
have maybe gathered I'm not a real big fan of AS's dependence on the D&T CP
for formatting - it makes it trickier to write machine-independent code as
you've got to be very careful what you do with dates as strings. I'd much
prefer a more feature-complete date class that allowed the script to
specify "%d/%m/%y" and/or "dd/mm/yy" style formatting for both
date-to-string and string-to-date coercions. In the meantime, I just patch
the gap for myself. (One of these days I might even come up with a version
of dateLib that I'm actually happy with and release the blighter...;)


Cheers

has
_______________________________________________
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.

  • Prev by Date: Re: Create a folder with today's date as the folder name
  • Next by Date: Apple System Profiler in OS10.1.2 opens OS9.2
  • Previous by thread: monthNumber (was: Create a folder with today's date...)
  • Next by thread: Re: monthNumber (was: Create a folder with today's date...)
  • Index(es):
    • Date
    • Thread