diff options
author | Cassio Neri <cassio.neri@gmail.com> | 2021-02-24 17:33:45 +0000 |
---|---|---|
committer | Jonathan Wakely <jwakely@redhat.com> | 2021-02-24 17:58:48 +0000 |
commit | 97d6161f6a7fa712622fc4e384fcb07e2ff5a127 (patch) | |
tree | ef1b09dd948e42cf1beb296c922b6ca4610477ba /libcpp | |
parent | 3dfd5493cf9798d46dd24ac32becc54d5074271e (diff) | |
download | gcc-97d6161f6a7fa712622fc4e384fcb07e2ff5a127.zip gcc-97d6161f6a7fa712622fc4e384fcb07e2ff5a127.tar.gz gcc-97d6161f6a7fa712622fc4e384fcb07e2ff5a127.tar.bz2 |
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.
Diffstat (limited to 'libcpp')
0 files changed, 0 insertions, 0 deletions