Originally shared by David Berneda
Originally shared by David Berneda
A slightly optimized TDateTime functions (YearOf, MonthOf, DayOf)
https://github.com/davidberneda/FastDateTime
Aprox 41%, 23%, 24% faster, respectively
A slightly optimized TDateTime functions (YearOf, MonthOf, DayOf)
https://github.com/davidberneda/FastDateTime
Aprox 41%, 23%, 24% faster, respectively
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.
ReplyDeletehttp://stackoverflow.com/questions/20270596/how-do-i-implement-an-efficient-32-bit-divmod-in-64-bit-code
David Heffernan Thank you David ! I just grabbed the DivMod purepascal version from DateUtils. Using System.Math DivMod is now faster in both 32 and 64 bit
ReplyDeleteHowever, after profiling it shows the bottleneck (40% of time) is at the "while True" loop that guesses the month number from the day-of-the-year number.
ReplyDeleteI've tried replacing the loop with 12 big nested "if" blocks (one per month, without using the MonthDays arrays) but the improvement is minuscule (and the code is ugly)
Integer math (:
ReplyDeleteDavid Berneda
ReplyDeleteuse a lookup table
/sub
ReplyDeleteJohan Bontes yes, that's the definitive solution (two const arrays of byte, 365 and 366 elements)
ReplyDeleteJohan Bontes and two more arrays, to obtain the day in the month
ReplyDeleteDavid Berneda Cool! Is that optimisation on GitHub yet?
ReplyDeleteJavier Hernández which would be very incompatible with people having a Delphi-only license of either the IDE or the 3rd party library involved. No more MidasLib.dcu headaches please...
ReplyDeleteJeroen Wiert Pluimers hehe no, and I'm on vacation til next monday. I can try with my mobile phone editing on github directly, but no compiler to test :-)
ReplyDeleteDavid Berneda enjoy your holiday.
ReplyDelete/sub
ReplyDeleteUpdated code, added lookup-table optimizations, Lazarus / FPC support and test project:
ReplyDeletehttps://github.com/davidberneda/FastDateTime
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/).
ReplyDeleteBut in this FastDateTime code the test project uses TStopWatch (GetTickCount in FPC) to compare speed