public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "Daniel Berlin" <dberlin@dberlin.org>
To: gcc-bugzilla@gcc.gnu.org
Cc: gcc-bugs@gcc.gnu.org
Subject: Re: [Bug libstdc++/30203] New: std::vector::size() 10x speedup (patch)
Date: Fri, 15 Dec 2006 05:27:00 -0000 [thread overview]
Message-ID: <4aca3dc20612142127p24619b74y87408c131e6e41e5@mail.gmail.com> (raw)
In-Reply-To: <bug-30203-13750@http.gcc.gnu.org/bugzilla/>
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
<gcc-bugzilla@gcc.gnu.org> 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 <vector>
> int main () {
> std::vector<int> x (100);
> unsigned long l = 0;
> const unsigned long iterations = 100000000;
> for (unsigned long i=0; i<iterations; ++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 <vector>
> int main () {
> std::vector<int> x (100);
> unsigned long l = 0;
> const unsigned long iterations = 100000000;
> for (unsigned long i=0; i<iterations; ++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
>
>
prev parent reply other threads:[~2006-12-15 5:27 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-12-13 17:38 charles at rebelbase dot com
2006-12-13 18:07 ` [Bug libstdc++/30203] " chris at bubblescope dot net
2006-12-14 2:48 ` pinskia at gcc dot gnu dot org
2006-12-14 10:20 ` pcarlini at suse dot de
2006-12-14 17:59 ` charles at rebelbase dot com
2006-12-15 5:27 ` dberlin at dberlin dot org
2006-12-15 5:27 ` Daniel Berlin [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4aca3dc20612142127p24619b74y87408c131e6e41e5@mail.gmail.com \
--to=dberlin@dberlin.org \
--cc=gcc-bugs@gcc.gnu.org \
--cc=gcc-bugzilla@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).