Other Date/Time Articles:A Very Fast 64–Bit Date Algorithm: 30–40% fasterCounting years backwards unlocks faster speed.The first date algorithm to use only 4 multiplications, instead of 7+.23 November 2025In this article I present my final very fast date conversion algorithm. It represents a significant speed gain — being similar in magnitude to the speed gains achieved by the previous fastest algorithm (Neri-Schneider 2021) over its predecessor (C++ Boost). The full algorithm implementation in C++ is released as free open source software (BSL-1.0 License).The algorithm provides accurate results over a period of ±1.89 Trillion years, making it suitable to process the full UNIX 64–bit time (in seconds).The entire algorithm has been re-written top-to-bottom, with various micro-optimisations, but three main new ideas:Years are calculated backwards, which removes various intermediate steps.The step to calculate day-of-year is skipped, instead using a year-modulus-bitshift technique which removes a division.The "Julian Map" technique is utilised from my previous article, which speeds up the 100/400 year calculation, removing two more hardware multiplications.While fast date algorithms have always used 7 or more expensive computations (multiplication, division, or modulus by non-power-of-2 numbers), this algorithm uses only 4 multiplications. The speed-gain can be seen at a glance.Relative Speeds of Fastest AlgorithmsAs tested on Intel x64 and Apple M4 Pro processors(smaller numbers = faster)See benchmark sectionfor further information.C++ Boost(2012)2.4×Neri-Schneider(2021)1.6×This Algorithm(2025)1×The benchmark results match what is expected by hand-counting operations:Approx. CPU Cycles Comparison (x64)AlgorithmMultiplications `M`(non-power-of-2)Basic Operations `B`e.g. Add, Shift, LEA etc.Approx Cycles3 * M + BC++ Boost102151Neri-Schneider71940This Algorithm41527I will first present the general algorithm in pseudocode, then explain why it counts years backwards, then ...
First seen: 2025-11-26 18:31
Last seen: 2025-11-27 16:38