]> git.ipfire.org Git - thirdparty/gcc.git/commit
libstdc++: More efficient days from date
authorCassio Neri <cassio.neri@gmail.com>
Wed, 24 Feb 2021 17:33:45 +0000 (17:33 +0000)
committerJonathan Wakely <jwakely@redhat.com>
Wed, 24 Feb 2021 17:58:48 +0000 (17:58 +0000)
commit97d6161f6a7fa712622fc4e384fcb07e2ff5a127
treeef1b09dd948e42cf1beb296c922b6ca4610477ba
parent3dfd5493cf9798d46dd24ac32becc54d5074271e
libstdc++: More efficient days from date

This patch reimplements std::chrono::year_month_day::_M_days_since_epoch()
which calculates the number of elapsed days since 1970/01/01.  The new
implementation is based on Proposition 6.2 of Neri and Schneider, "Euclidean
Affine Functions and Applications to Calendar Algorithms" available at
https://arxiv.org/abs/2102.06959.

The aforementioned paper benchmarks the implementation against several
counterparts, including libc++'s (which is identical to the current
implementation).  The results, shown in Figure 3, indicate the new algorithm is
1.7 times faster than the current one.

The patch adds a test which loops through all dates in [-32767/01/01,
32767/12/31], and for each of them, gets the number of days and compares the
result against its expected value. The latter is calculated using a much
simpler and easy to understand algorithm but which is also much slower.

The dates used in the test covers the full range of possible values
[time.cal.year.members].  Despite its completeness the test runs in matter of
seconds.

libstdc++-v3/ChangeLog:

* include/std/chrono (year_month_day::_M_days_since_epoch):
New implementation.
* testsuite/std/time/year_month_day/4.cc: New test.
libstdc++-v3/include/std/chrono
libstdc++-v3/testsuite/std/time/year_month_day/4.cc [new file with mode: 0644]