benjoffe
The `new` thing is the range-splitting which achieves the floor division for negative inputs (eg. sign-selected for 60% of divisors, and the negative/positive bump for the remaining 20%/20% of cases each).
Show HN: A Zoomable Equal-Area Map Projection that interpolates to Mercator
A faster way to convert a timestamp to Hour, Min, Sec
I have a mobile-friendly web-app where you can practice this technique, just click the link in the page's nav: "Weekle - Weekday Guessing Game"
I would not normally spend such effort, but in this case I felt that the functions were too hard to understand without the visual aid, and too difficult to customise without the Function Explorer.
Then I think I just got a bit carried away with the detail.
A new 2-3x faster algorithm for computing day-of-week
(The link in the submission is incorrect; apologies for the confusion.)
The article outlines the technique, shows related developments before and after its creation, and includes an interactive, human-verifiable "proof".
A faster is_leap_year function (full-range, C++)
It might also come into play if developing SIMD alternatives for batch date processing, as one can have more lanes with 16-bit. I plan to make a blog post covering SIMD and if 16-bit algorithms have reasonable performance then that will be covered.
When I started the blog series, I expected the first article to be the most noteworthy, with the 2nd and 3rd being lesser supplementary topics.
Now that the 3rd blog post ended up with a much larger result than I was expecting, it stands on its own and could do with some editing as you suggest.
Displaying the months like the following helps see the regularity at a glance. Columns 1, 3 and 5 are the long months, others being shorter:
+-----+-----+-----+-----+-----+
| 31 | 30 | 31 | 30 | 31 |
| I | II | III | IV | V |
| MAR | APR | MAY | JUN | JUL |
|-----+-----+-----+-----+-----+
| 31 | 30 | 31 | 30 | 31 |
| VI |VII |VIII | IX | X |
| AUG | SEP | OCT | NOV | DEC |
+-----+-----+-----+-----+-----+
| 31 |28/29|
| XI |XII |
| Jan | FEB |
+-----+-----+
> To a person who natively thinks in Roman numerals, remembering that the short months are: II, VII, XII, along with IV & IX would be much easier than the way us modern folks have to memorise it.I was fortunate enough to be programming on an ARM based device, which meant that the terms (x * 4 + 3) strongly stood out to me as highly inefficient, being 2 cycle prep for the more important division. On x64 computers, those two operations are calculated in only one operation by using the 'LEA' assembly instruction (which I wasn't aware of at the time), and so others using that type of computer might not have felt this step needed any simplification.
I tried everything under the sun to get rid of these steps. The technique noted in the article of using the year 101 BC was for a long time my strongest candidate, you can view the implementation of that attempt at the link below [1].
An epoch of 101 BC still meant that there was extra work required to re-normalise the timeline after the century calculation, but it was only a single addition of 365 in the calculation of `jul`. The explanation of how this works is probably a whole blog post in itself, but now that this algorithm has been discarded it's not worth the time to explain it fully.
I also had the year-modulus-bitshift technique developed at that time, but it couldn't be integrated cleanly with any of my algorithm attempts yet. My plan was to simply document it as an interesting but slower concept.
I don't know what sparked the idea of going backwards other than immersing myself deeply in the problem in my spare time for about a month. It finally came to me one evening, and I thought it was only going to save 1-cycle, but when it also meant the year-modulus-bitshift could be utilised, the entire thing fit together like a glove and the speed collapsed down from 20% time saving to 40%.
[1] https://github.com/benjoffe/fast-date-benchmarks/blob/218356...
Show HN: A faster day-count to Y,M,D algorithm – 30-40% speedup
https://www.benjoffe.com/fast-date-64
Converting that integer to a Year, Month and Day is a fundamental calculation made in almost all programming languages and standard libraries. It runs every time a date is displayed, whether it's in a user interface, log, API etc.While it is rarely a bottleneck, it is a very frequently run algorithm, and thus has attracted a lot of attention over the years.In 2021, Cassio Neri and Lorenz...
It achieves a 30–40% speed improvement on x86-64 and ARM64 (Apple M4 Pro) by reversing the direction of the year count and reducing the operation count (4 multiplications instead of the usual 7+).
Paper-style explanation, benchmarks on multiple architectures, and full open-source C++ implementation.
A Fast 64-Bit Date Algorithm (30–40% faster by counting dates backwards)
A New Faster Algorithm for Gregorian Date Conversion
The Smoital System – A method of timekeeping on Mars based on UTC
If you don't have time to read, you may want to quickly check "Appendix A" for the “Smoitus” chart to see visually how the timezone alignment systems works, and "Section 5: Equation of Time (Smoital System)" to see how well this system tracks solar time.
The goal of the web app is more about the practice modes and daily game, people are free to use Doomsday for these if they like.
All three date formats are used in Weekle when set to Canadian mode, and fully numeric d/m/y or m/d/y dates are only used if the date is >12 to avoid ambiguity.
Even if it works, I'll probably take your suggestion add a tip below the date to clarify the date format for the user's first session.
I recommend only attempting to memorise the table after you are already able to calculate the year number using the normal algorithm.
Show HN: Weekle – a web app to learn how to calculate the day of the week
Mentally calculating the day-of-the-week for any date in history sounds like an impossible task for a normal person, but the algorithm is actually pretty simple to learn.Although there are tutorials for this elsewhere online, and little quizzes available, there didn't seem to be anything well optimised with multiple practice modes etc.I originally created a basic version of this just for...