calculate date_from_iso_days using neri_schneider algorithm#14999
calculate date_from_iso_days using neri_schneider algorithm#14999josevalim merged 2 commits intoelixir-lang:mainfrom
Conversation
|
|
||
| days_in_previous_years(year) + days_before_month(month) + leap_day_offset(year, month) + day - | ||
| 1 | ||
| y = if month <= 2, do: year - 1, else: year |
There was a problem hiding this comment.
Maybe we could mention the name of the algorithm in a comment with a link for future reference?
|
Was very intrigued, took a look and stumbled across this recent article claiming to surpass Neri-Schneider. A New Faster Algorithm for Gregorian Date Conversion - also note the mention of an even faster version by now. It might be of interest, if not, apologies for the noise :) |
Same here: this new algorithm made me curious how we do it. :) The mentioned algorithm from last week is implemented in c and uses compiler tricks that can't be implemented on the beam: like bit shifting a 128bit number by 64bits that is 'free' on modern computers. |
|
here a benchmark for the function date_to_iso_days: |
|
💚 💙 💜 💛 ❤️ |
This is a faster implementation than the erlang one. The reference implementation is mit licensed I adjusted it for elixir needs using windsurf with claude opus.
2x speedup comparing to the version from last week.