YEAR = OCONV(THE.DATE, "DY")
EGIN CASE
CASE MOD(YEAR,4); LEAP.YEAR = FALSE
ASE MOD(YEAR, 100); LEAP.YEAR = TRUE
ASE MOD(YEAR, 400); LEAP.YEAR = FALSE
CASE 1; LEAP.YEAR = TRUE
ND CASE





-----Original Message-----
From: David A. Green <dgr...@dagconsulting.com>
To: 'Daniel McGrath' <dmcgr...@rocketsoftware.com>; 'U2 Users List' 
<u2-users@listserver.u2ug.org>
Sent: Wed, Dec 7, 2011 12:23 pm
Subject: Re: [U2] End of Month date routine


Okay I took the fastest routine and made it into an $INSERT piece of code:
YEAR = OCONV(THE.DATE, "DY")
F MOD(YEAR,4) THEN
  LEAP.YEAR = 0
ND ELSE
  IF MOD(YEAR, 100) THEN
     LEAP.YEAR = 1
  END ELSE 
     IF MOD(YEAR, 400) THEN LEAP.YEAR = 0 ELSE LEAP.YEAR = 1
  END
ND
Then created a Function like:
UNCTION LEAP.YEAR.FUN( THE.DATE )
INSERT LEAP.YEAR.INS
ETURN LEAP.YEAR
And a Subroutine like:
UBROUTINE LEAP.YEAR.SUB( LEAP.YEAR, THE.DATE )
INSERT LEAP.YEAR.INS
ETURN
Then modified Daniel's test program like:
EFFUN LEAP.YEAR.FUN( THE.DATE )
QU LC TO 10000000

T = TIME()
OR THE.DATE = 1 TO LC
  LEAP.YEAR = LEAP.YEAR.FUN( THE.DATE )
EXT THE.DATE
S = TIME()
RT TS - ST


T = TIME()
OR THE.DATE = 1 TO LC
 CALL LEAP.YEAR.SUB( LEAP.YEAR, THE.DATE )
EXT THE.DATE
S = TIME()
RT TS - ST

T = TIME()
OR THE.DATE = 1 TO LC
 $INSERT LEAP.YEAR.INS
EXT THE.DATE
S = TIME()
RT TS - ST

ND
The speed results:
unction 24 seconds
ubroutine 21 seconds
nsert 11 seconds
Not surprising results given what we know about these three methods.
lthough the function method did get better since the last time I've test
t.
UD 6.1
Other systems will vary.
But this is a good example of working together to enhance the U2 products,
ow we all have the same Leap Year calculation and those that were using the
OD(YEAR, 4) method should now use this method everywhere as to avoid data
orruption.
David A. Green
480) 813-1725
AG Consulting

----Original Message-----
rom: Daniel McGrath [mailto:dmcgr...@rocketsoftware.com] 
ent: Wednesday, December 07, 2011 11:57 AM
o: dgr...@dagconsulting.com; U2 Users List
ubject: RE: [U2] End of Month date routine
I added the code to PasteBin so as to not flood here:
ttp://pastebin.com/JMyqhFud
I did a few more than 100K and I cut the OCONV step out from all of them. I
ook the liberty to adjust Will's version to return correct results. The
esults I got, in order, was:
16.872
.804
.384
.561
So, if you have a need to account for your milliseconds, the slightly
ptimized Wikipedia algorithm seems to be the fastest.
Interested to see if there are any better? (Or if I made any mistakes...)
Regards,
an
-----Original Message-----
rom: u2-users-boun...@listserver.u2ug.org
mailto:u2-users-boun...@listserver.u2ug.org] On Behalf Of David A. Green
ent: Wednesday, December 07, 2011 10:48 AM
o: 'U2 Users List'
ubject: Re: [U2] End of Month date routine
Who wants to take each of the Leap Year calculations and put them into
ifferent subroutines and loop 100K times and see which one is faster using
rofiling?
David A. Green
480) 813-1725
AG Consulting
_______________________________________________
2-Users mailing list
2-us...@listserver.u2ug.org
ttp://listserver.u2ug.org/mailman/listinfo/u2-users
_______________________________________________
2-Users mailing list
2-us...@listserver.u2ug.org
ttp://listserver.u2ug.org/mailman/listinfo/u2-users

_______________________________________________
U2-Users mailing list
U2-Users@listserver.u2ug.org
http://listserver.u2ug.org/mailman/listinfo/u2-users

Reply via email to