Get the latest tech news
A leap year check in three instructions
How to test for leap years (until year 102499) in the proleptic Gregorian calendar with just three 32-bit instructions, with detailed explanation of the bit-level tricks.
I couldn't immediately find a way to prove it, so I employed the tried-and-true method of getting someone else to do it for me by posting it to the Code Golf StackExchange. The new function is_leap_year_fast is 3.8 times faster than the standard implementation for random data, and about 6% slower for the perfectly predictable input. To fully justify a change, ideally we would have a benchmark with realistic data that employs a leap year check as a subroutine, rather than just microbenchmarking.
Or read this on Hacker News