"Oplec" <anonymous@anonymous.cp> wrote in message
news:ISBmb.57188$h61.34769@news01.bloor.is.net.cab le.rogers.com...[color=blue]
> From what I have read, to measure elapsed time one would:
>
> #include <ctime>
>
> clock_t start = clock();
> do_something();
> clock_t end = clock();
> double time_elapsed = double(end - start)/CLOCKS_PER_SEC;[/color]
Yes, this is the basic idea. The code you pointed to just
does a bunch of additional tricks to try to optimize
the accuracy of the result.
Like, for example:
// Wait for the clock to tick
clock_t k = clock();
clock_t start;
do start = clock();
while (start == k);
The point of this code is to wait until the clock just advances,
to ensure we start measuring time right after a tick (and not
anywhere between two ticks -- which would mean that only
some fraction of the first tick interval would be used for
the code to run).
Also, other code attempts to subtract the overhead of the
calls to clock themselves.
[color=blue]
> Do any of you have the article and could explain it to me, or perhaps look
> at the code and explain why so many clock()'s are used?
>
> The link is:
http://www.research.att.com/~bs/wrap_code.cpp[/color]
The above should explain all the uses of clock() that I can
see in the code above.
Please let me know if something else remains unclear...
Regards,
Ivan
--
http://ivan.vecerina.com