
Measuring algorithm speed
Quote:
>I want to measure the time taken to perform an algorithm.
>time_t now, after, time_taken;
>now = time(NULL);
>/* do the algorithm here */
>after = time(NULL);
>time_taken = after - now;
Usually it is better to use clock() rather than time() since this measures
CPU time rather than wall-clock time.
Quote:
>Unfortunately the granularity of time_t is in seconds.
>But the algorithm is performed in milliseconds.
>Is there another way?
The granularity of clock() is often subsecond but C makes no guarantees.
To time something that takes a short period you either find some special
feature of your particular system that allwos this or (more typically)
you repeat the operation a large number of times and measure the
overall time.
--
-----------------------------------------
-----------------------------------------