Ben's implementation handles negative years, mine doesn't. Ben's implementation avoids %19, mine doesn't. I haven't benchmarked the two. But I basically just copied my algorithm from Calendrical Calculations as noted at the above link. I'd bet money Ben's work on optimizations has produced faster code than what I posted.
Nice read Ben!
Fwiw, curiosity got the best of me, and I tested my chrono implementation against Ben's over the range of years [0, 32767], which is a tiny slice of the range of validity of Ben's implementation.
Correctness: Both implementations get the same answers over this range.
Performance: I didn't do any timings, but I looked at the assembly at -O3. Ben's assembly is significantly shorter than mine, and is branchless. Mine has two branches. Neither has loops. Both are going to be fast. But Ben's will be faster. Not sure by how much, but I'm sure by a healthy percentage.
Disclaimer: I only tested Ben's "return day index" version.
6
u/VinnieFalco wg21.org | corosio.org 25d ago
Great article! Curious to hear Howard Hinnant's thoughts on this