Updated code, added lookup-table optimizations, Lazarus / FPC support and test project:
A slightly optimized TDateTime functions (YearOf, MonthOf, DayOf) …
Posted by jpluimers on 2017/07/13
Besides the optimised versions of these functions, I learned the most from these comments:
The DivMod should be faster. Should really be a single division. The CPU instruction will give you both div and mod from a single instruction. No point doing the divide twice.+Javier Hernández In the past I used AQTime but now I’m using NexusDB Quality suite (http://www.nexusdb.com/support/index.php?q=qualitysuite) and +Eric Grange SamplingProfiler (https://www.delphitools.info/samplingprofiler/).
But in this FastDateTime code the test project uses TStopWatch (GetTickCount in FPC) to compare speed
–jeroen
Source: A slightly optimized TDateTime functions (YearOf, MonthOf, DayOf) …
rvelthuis said
Note that in 10.2 Tokyo, the $IFDEF in System.Math seems to be wrong. That is why 64 bit DivMod returns the PUREPASCAL version, doing a div and a mod, while there is actually a proper assembler version doing only one 64 bit division. The latter is never called.
jpluimers said
Thanks!