A faster day-count to Y,M,D algorithm – 30-40% speedup
A faster day-count to Y,M,D algorithm – 30-40% speedup
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 Schneider developed the Neri-Schneider algorithm, which was a major breakthrough in this niche area. Lately, I have been studying this function deeply, and found what I believe may be the last remaining substantial improvements achievable on current hardware. The gains come mainly from counting dates backwards, and from reducing the number of multiplications from 7 to 4. Adoption will depend on whether library maintainers consider the performance benefit to outweigh the readability. If this is rejected on readability grounds, then in those cases my algorithm outlined in Article 1 (linked in the blog post navigation) is likely to be simpler and faster than what almost all existing libraries are currently doing. I found this a very interesting challenge to work on, and I believe some of the techniques outlined may be applicable to other areas of optimisation.
Share cardActual performance
Launch Intel predictions
Analyze your own launch →Incorrect prediction on native model
Similar products
BM25opt – 30-40 x faster BM25 search algorithms (FOSS)
Cython implementation of DeepWalk algorithm
Illustrated Quicksort algorithm
Prim's algorithm
DFA Minimization by Hopcroft's Algorithm in Go
Polyline Encoding Algorithm in Dart
Mandelwave: A mandelbrot inverse spectrogram with Griffin-Lim algorithm
Go implementation of Welford's algorithm for weighted variance
Distributed Genetic Algorithm in Clojure
K-means algorithm in Ruby