From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id 8F17C38708EC for ; Wed, 24 Feb 2021 17:28:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 8F17C38708EC Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-27-bBGOpG3NPoqUts_woCnsCg-1; Wed, 24 Feb 2021 12:28:29 -0500 X-MC-Unique: bBGOpG3NPoqUts_woCnsCg-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1AC51364DB; Wed, 24 Feb 2021 17:28:28 +0000 (UTC) Received: from localhost (unknown [10.33.36.11]) by smtp.corp.redhat.com (Postfix) with ESMTP id 990961001E73; Wed, 24 Feb 2021 17:28:27 +0000 (UTC) Date: Wed, 24 Feb 2021 17:28:26 +0000 From: Jonathan Wakely To: cassio.neri@gmail.com Cc: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: Re: [PATCH 1/4] libstdc++: More efficient date from days. Message-ID: <20210224172826.GZ3008@redhat.com> References: MIME-Version: 1.0 In-Reply-To: X-Clacks-Overhead: GNU Terry Pratchett X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline X-Spam-Status: No, score=-8.2 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=unavailable autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libstdc++@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++ mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 24 Feb 2021 17:28:43 -0000 On 23/02/21 13:24 +0000, Cassio Neri via Libstdc++ wrote: >This patch reimplements std::chrono::year_month_day::_S_from_days() which >retrieves a date from the number of elapsed days since 1970/01/01. The new >implementation is based on Proposition 6.3 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 4, indicate the new algorithm is >2.2 times faster than the current one. > >The patch adds a test which loops through all integers in [-12687428, 11248737], >and for each of them, gets the corresponding date 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 interval used in the test covers the full range of values for which a >roundtrip must work [time.cal.ymd.members]. Despite its completeness the test >runs in a matter of seconds. > >libstdc++-v3/ChangeLog: > > * include/std/chrono: > * testsuite/std/time/year_month_day/3.cc: New test. Thanks! I'm committing this to trunk (it only changes new C++20 material so OK during stage 4 ... and anyway it's both faster and better tested than the old code). I've tweaked it slightly to keep some lines below 80 columns, but no changes except whitespace.