From: "Diego Novillo" <dnovillo@google.com>
To: "Wesley Smith" <wesley.hoke@gmail.com>
Cc: "MSX to GCC" <gcc-help@gcc.gnu.org>
Subject: Re: stack variables and loops
Date: Wed, 19 Mar 2008 13:18:00 -0000 [thread overview]
Message-ID: <b798aad50803190617n64e73645x7eeae4cb6ec92be9@mail.gmail.com> (raw)
In-Reply-To: <1079b050803182236ud33b5bfqe4148ff53dcc2681@mail.gmail.com>
2008/3/19 Wesley Smith <wesley.hoke@gmail.com>:
> Vec3 *v = vectors;
> for(int i=0; i < 100; i++) {
> Vec3 v_rand;
> v_rand.random(); //make a random vector;
>
> *v++ += v_rand;
> }
>
>
> /////example 2
>
> Vec3 *v = vectors;
> Vec3 v_rand;
> for(int i=0; i < 100; i++) {
> v_rand.random(); //make a random vector;
>
> *v++ += v_rand;
> }
>
>
> Clearly there are scope differences between the 2 examples, but in
> terms of performance, how do compilers handle these situations.
The first version needs to have a ctor and dtor call invoked on every
iteration of the loop. Depending on what they do that will slow the
code down. If you insert a printf() call in Vec3's constructor and
destructor you'll see the difference. With GCC 4+ you can also use
-fdump-tree-gimple to get a C-like representation of your program.
Diego.
next prev parent reply other threads:[~2008-03-19 13:18 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-03-19 5:36 Wesley Smith
2008-03-19 13:18 ` Diego Novillo [this message]
2008-03-19 15:24 ` Wesley Smith
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=b798aad50803190617n64e73645x7eeae4cb6ec92be9@mail.gmail.com \
--to=dnovillo@google.com \
--cc=gcc-help@gcc.gnu.org \
--cc=wesley.hoke@gmail.com \
/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).