performance measure for optimized c++ code

Discussion in 'C++' started by gautamcool88@gmail.com, Jul 9, 2008.

  1. Guest

    I want to measure the execution time of a function, which is in the
    order of microseconds. The approach I am using right now is to call
    the function a sufficient number of times so that the cumulative time
    is measurable, then divide the cumulative time by the number of times
    the function was called.

    I have some doubts about this approach -
    With full compiler optimizations, I am not sure if the compiler is
    making use of the facts that
    (a). the input arguments to the function remain the same (and hence
    the output is also the same) each time the function is called.
    (b) that I am not making use of the output. (not printing to a file/
    stdout).

    So the compiler might be executing the function partially or in a
    different manner. I do not want that, as it will obviously give a
    misleading results.

    At the same time, I do want "normal" optimizations. (Which do not make
    use of points (a) and (b) mentioned above). Any suggestions for
    this?

    (The function can not contain any cout statements because that would
    severely change its running time.)
    , Jul 9, 2008
    #1
    1. Advertising

  2. Sleipnir Guest

    give us your function... we will see



    <> a écrit dans le message de
    news:...
    >I want to measure the execution time of a function, which is in the
    > order of microseconds. The approach I am using right now is to call
    > the function a sufficient number of times so that the cumulative time
    > is measurable, then divide the cumulative time by the number of times
    > the function was called.
    >
    > I have some doubts about this approach -
    > With full compiler optimizations, I am not sure if the compiler is
    > making use of the facts that
    > (a). the input arguments to the function remain the same (and hence
    > the output is also the same) each time the function is called.
    > (b) that I am not making use of the output. (not printing to a file/
    > stdout).
    >
    > So the compiler might be executing the function partially or in a
    > different manner. I do not want that, as it will obviously give a
    > misleading results.
    >
    > At the same time, I do want "normal" optimizations. (Which do not make
    > use of points (a) and (b) mentioned above). Any suggestions for
    > this?
    >
    > (The function can not contain any cout statements because that would
    > severely change its running time.)
    Sleipnir, Jul 9, 2008
    #2
    1. Advertising

  3. Dijkstra Guest

    On 9 jul, 15:16, "" <>
    wrote:
    > I want to measure the execution time of a function, which is in the

    [...]
    > I have some doubts about this approach -
    > With full compiler optimizations, I am not sure if the compiler is
    > making use of the facts that

    [...]
    > So the compiler might be executing the function partially or in a
    > different manner. I do not want that, as it will obviously give a
    > misleading results.


    The compiler does not "execute" nothing. But I understand what you
    mean. The compiler only optimizes what it can see at compile time,
    nothing more, nothing less. You can separate your target function and
    the loop in two distinct modules, so you will be pretty sure the
    compiler will not fold the loop.

    Cheers,
    Dijkstra.
    Dijkstra, Jul 10, 2008
    #3
  4. James Kanze Guest

    On Jul 10, 1:23 am, Dijkstra <> wrote:
    > On 9 jul, 15:16, "" <>
    > wrote:


    > > I want to measure the execution time of a function, which is in the

    > [...]
    > > I have some doubts about this approach -
    > > With full compiler optimizations, I am not sure if the compiler is
    > > making use of the facts that

    > [...]
    > > So the compiler might be executing the function partially or in a
    > > different manner. I do not want that, as it will obviously give a
    > > misleading results.


    > The compiler does not "execute" nothing. But I understand what you
    > mean. The compiler only optimizes what it can see at compile time,
    > nothing more, nothing less. You can separate your target function and
    > the loop in two distinct modules, so you will be pretty sure the
    > compiler will not fold the loop.


    Unless you're using Sun CC. Or VC++. Or any one of a number of
    other compilers which can optimize across translation
    boundaries. (Of course, you usually need special options for
    such optimization.)

    My own solution has been to make the function virtual, which
    seems to suffice for the compilers I currently use (but I have
    no guarantees for the future). And I do ensure that the
    function "does something" which affects global state. And that
    the same call point uses different types of objects (and thus
    resolves to a different function) at different times in the
    execution. (Amongst other things, I make a dry run, with an
    empty virtual function, to establish a base value, which is then
    subtracted from all of the other run times.)

    The only way to be sure, of course, is to look at the code the
    compiler is generating, and determine manually if the
    optimizations it is doing are falsifying the measurement. And
    to be cleverer than the authors of the compiler.

    --
    James Kanze (GABI Software) email:
    Conseils en informatique orientée objet/
    Beratung in objektorientierter Datenverarbeitung
    9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
    James Kanze, Jul 10, 2008
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jeff S

    Measure Performance Tuning Efforts

    Jeff S, Dec 4, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    382
    Jeff S
    Dec 5, 2003
  2. Gaurav
    Replies:
    10
    Views:
    575
    Anon Amous
    Jun 18, 2004
  3. Gaurav
    Replies:
    127
    Views:
    1,989
    Walter
    Jun 23, 2004
  4. Replies:
    6
    Views:
    387
  5. Bond

    Measure Performance

    Bond, Jul 11, 2005, in forum: Javascript
    Replies:
    1
    Views:
    63
Loading...

Share This Page