From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 28099 invoked by alias); 15 Dec 2006 05:27:32 -0000 Received: (qmail 28084 invoked by uid 22791); 15 Dec 2006 05:27:31 -0000 X-Spam-Check-By: sourceware.org Received: from wx-out-0506.google.com (HELO wx-out-0506.google.com) (66.249.82.227) by sourceware.org (qpsmtpd/0.31) with ESMTP; Fri, 15 Dec 2006 05:27:27 +0000 Received: by wx-out-0506.google.com with SMTP id h31so630643wxd for ; Thu, 14 Dec 2006 21:27:25 -0800 (PST) Received: by 10.90.104.14 with SMTP id b14mr391398agc.1166160445587; Thu, 14 Dec 2006 21:27:25 -0800 (PST) Received: by 10.90.73.9 with HTTP; Thu, 14 Dec 2006 21:27:25 -0800 (PST) Message-ID: <4aca3dc20612142127p24619b74y87408c131e6e41e5@mail.gmail.com> Date: Fri, 15 Dec 2006 05:27:00 -0000 From: "Daniel Berlin" To: gcc-bugzilla@gcc.gnu.org Subject: Re: [Bug libstdc++/30203] New: std::vector::size() 10x speedup (patch) Cc: gcc-bugs@gcc.gnu.org In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline References: Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2006-12/txt/msg01336.txt.bz2 And what are the timings with a recent version of g++ and actually turning on optimization? On 13 Dec 2006 17:38:06 -0000, charles at rebelbase dot com wrote: > vector::size() in bits/stl_vector.h is currently implemented as > > size_type > size() const > { return size_type(end() - begin()); } > > A faster implementation is > > size_type > size() const > { return _M_impl._M_finish - _M_impl._M_start; } > > Which avoids the temporary iterators' life cycles > and operator- calls. > > I tried a simple timing test on both implementations, > and the latter appears to be 10x faster: > > (11:35:56)(charles xyzzy)(~): cat test.cc > #include > int main () { > std::vector x (100); > unsigned long l = 0; > const unsigned long iterations = 100000000; > for (unsigned long i=0; i l += x.size (); > return 0; > } > (11:35:58)(charles xyzzy)(~): g++ -o test test.cc -lstdc++ > (11:36:05)(charles xyzzy)(~): time ./test > > real 0m3.692s > user 0m3.676s > sys 0m0.004s > (11:36:10)(charles xyzzy)(~): cat test2.cc > #include > int main () { > std::vector x (100); > unsigned long l = 0; > const unsigned long iterations = 100000000; > for (unsigned long i=0; i l += x._M_impl._M_finish - x._M_impl._M_start; > return 0; > } > (11:36:13)(charles xyzzy)(~): g++ -o test2 test2.cc -lstdc++ > (11:36:19)(charles xyzzy)(~): time ./test2 > > real 0m0.342s > user 0m0.336s > sys 0m0.004s > > > -- > Summary: std::vector::size() 10x speedup (patch) > Product: gcc > Version: unknown > Status: UNCONFIRMED > Severity: enhancement > Priority: P3 > Component: libstdc++ > AssignedTo: unassigned at gcc dot gnu dot org > ReportedBy: charles at rebelbase dot com > > > http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30203 > >