Okay I took the fastest routine and made it into an $INSERT piece of code: YEAR = OCONV(THE.DATE, "DY") IF MOD(YEAR,4) THEN LEAP.YEAR = 0 END ELSE IF MOD(YEAR, 100) THEN LEAP.YEAR = 1 END ELSE IF MOD(YEAR, 400) THEN LEAP.YEAR = 0 ELSE LEAP.YEAR = 1 END END
Then created a Function like: FUNCTION LEAP.YEAR.FUN( THE.DATE ) $INSERT LEAP.YEAR.INS RETURN LEAP.YEAR And a Subroutine like: SUBROUTINE LEAP.YEAR.SUB( LEAP.YEAR, THE.DATE ) $INSERT LEAP.YEAR.INS RETURN Then modified Daniel's test program like: DEFFUN LEAP.YEAR.FUN( THE.DATE ) EQU LC TO 10000000 * ST = TIME() FOR THE.DATE = 1 TO LC LEAP.YEAR = LEAP.YEAR.FUN( THE.DATE ) NEXT THE.DATE TS = TIME() CRT TS - ST * * ST = TIME() FOR THE.DATE = 1 TO LC CALL LEAP.YEAR.SUB( LEAP.YEAR, THE.DATE ) NEXT THE.DATE TS = TIME() CRT TS - ST * ST = TIME() FOR THE.DATE = 1 TO LC $INSERT LEAP.YEAR.INS NEXT THE.DATE TS = TIME() CRT TS - ST * END The speed results: Function 24 seconds Subroutine 21 seconds Insert 11 seconds Not surprising results given what we know about these three methods. Although the function method did get better since the last time I've test it. UD 6.1 Other systems will vary. But this is a good example of working together to enhance the U2 products, now we all have the same Leap Year calculation and those that were using the MOD(YEAR, 4) method should now use this method everywhere as to avoid data corruption. David A. Green (480) 813-1725 DAG Consulting -----Original Message----- From: Daniel McGrath [mailto:dmcgr...@rocketsoftware.com] Sent: Wednesday, December 07, 2011 11:57 AM To: dgr...@dagconsulting.com; U2 Users List Subject: RE: [U2] End of Month date routine I added the code to PasteBin so as to not flood here: http://pastebin.com/JMyqhFud I did a few more than 100K and I cut the OCONV step out from all of them. I took the liberty to adjust Will's version to return correct results. The results I got, in order, was: 16.872 2.804 2.384 5.561 So, if you have a need to account for your milliseconds, the slightly optimized Wikipedia algorithm seems to be the fastest. Interested to see if there are any better? (Or if I made any mistakes...) Regards, Dan -----Original Message----- From: u2-users-boun...@listserver.u2ug.org [mailto:u2-users-boun...@listserver.u2ug.org] On Behalf Of David A. Green Sent: Wednesday, December 07, 2011 10:48 AM To: 'U2 Users List' Subject: Re: [U2] End of Month date routine Who wants to take each of the Leap Year calculations and put them into different subroutines and loop 100K times and see which one is faster using profiling? David A. Green (480) 813-1725 DAG Consulting _______________________________________________ U2-Users mailing list U2-Users@listserver.u2ug.org http://listserver.u2ug.org/mailman/listinfo/u2-users _______________________________________________ U2-Users mailing list U2-Users@listserver.u2ug.org http://listserver.u2ug.org/mailman/listinfo/u2-users