On Jul 10, 1:23 am, Dijkstra <pepi...@gmail.comwrote:
On 9 jul, 15:16, "gautamcoo...@gmail.com" <gautamcoo...@gmail.com>
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:ja*********@gmail.com
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