Re: Leap Years
- Posted by MAP <ddhinc at ALA.NET> Mar 02, 1998
- 751 views
Craig wrote: > > Here's a lean version of leap year testing. I don't know how it > compares to others on speed. > ---------------- > global function leap_year(integer y) > -- return 1 for leap year, 0 for not > return ( integer(y/4)*(not integer(y/100)) + integer(y/400) ) > end function > ---------------- > First off, let me say that I don't think this is a function that really warrants much attention as far as optimization. But, I do like to play with optimization to improve my techniques, so I compared this function against the one I posted earlier just to see what the difference would be. The one I posted actually clocked at over 5 times faster than this version. This is probably due to your use of division. Division is the most expensive in machine cycles of the simple math operators. When speed is crucial, it should be avoided if possible. Many game programming books contain lengthy discussions just on techniques to avoid division. Christopher D. Hickman