Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > performance measure for optimized c++ code

Reply
Thread Tools

performance measure for optimized c++ code

 
 
gautamcool88@gmail.com
Guest
Posts: n/a
 
      07-09-2008
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.)
 
Reply With Quote
 
 
 
 
Sleipnir
Guest
Posts: n/a
 
      07-09-2008
give us your function... we will see



<(E-Mail Removed)> a écrit dans le message de
news:(E-Mail Removed)...
>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.)


 
Reply With Quote
 
 
 
 
Dijkstra
Guest
Posts: n/a
 
      07-09-2008
On 9 jul, 15:16, "(E-Mail Removed)" <(E-Mail Removed)>
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.
 
Reply With Quote
 
James Kanze
Guest
Posts: n/a
 
      07-10-2008
On Jul 10, 1:23 am, Dijkstra <(E-Mail Removed)> wrote:
> On 9 jul, 15:16, "(E-Mail Removed)" <(E-Mail Removed)>
> 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:(E-Mail Removed)
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
tool to measure performance of written function cranium.2003@gmail.com C Programming 6 05-09-2005 08:14 PM
Java's performance far better that optimized C++ Gaurav C++ 127 06-23-2004 02:55 AM
Java's performance far better that optimized C++ Gaurav Java 10 06-18-2004 06:33 AM
Measure Performance Tuning Efforts Jeff S ASP .Net 2 12-05-2003 07:24 PM
Output pixels, real measure of a digicam performance? Max Digital Photography 1 08-10-2003 05:48 PM



Advertisments