Implementing Fast Calendar Algorithms: Speeding Date
summary
Presents concrete, branch-free algorithms that map days-since-epoch to year/month/day using a computational-calendar transform plus integer arithmetic and reciprocal multiplication (Montgomery) to remove expensive divisions. Claims include 3× faster is_leap vs common implementations, a one-line branchless last-day formula for months ≠ 2, end-to-end code that runs in single-digit nanoseconds, and real-world adoption — in the Linux kernel, libstdc++ and .NET — with fewer multiplications and better parallelism on modern CPUs.
AI-written summary · about
chapters (19)
- 0:00Introduction
- 2:31Talk overview
- 8:20Modern calendar algorithms
- 10:28Roman and Julian history
- 15:26Gregorian reform and leap years
- 18:25Optimizing leap year checks
- 22:42Last day of month
- 24:54Mathematical framework
- 30:07Generalizing calendar calculations
- 31:55Framework for Julian calendar
- 35:26Computational calendar concept
- 37:59Mapping to calendars
- 41:11Date conversion algorithm
- 44:03Days since epoch
- 45:27Contributions and performance
- 46:50Optimizing division
- 50:48Montgomery reduction
- 52:13Historical bits and compilers
- 55:08Conclusion
related talks
55mCalendrical C++: std::chrono, History, Mathematics and the Computus
51mUsing std::chrono Calendar Dates for Finance in Cpp
59m“A C++14 approach to dates and times"
01h 00mMoving Faster: Everyday efficiency in modern C++
01h 21mHow Old Am I in Seconds? Insights From the C++ chrono Library
01h 01mAlgorithm Intuition (part 2 of 2)
59mC++20 - My Favourite Code Examples
01h 06mRebuilding Boost Date-Time for C++11
