Compare execution time in C language

Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
1 reply · 5K views
Vagrant
Messages
195
Reaction score
1

Homework Statement


I want to compare the execution times for DDA and Bresenham's Line algorithm using a C program. I used the clock_t command; I'm getting the execution time for Bresenham’s algorithm as 0.164835 but 0 for DDA.

3. The Attempt at a Solution

clock_t start,end;
start=clock();
Bresenham's line algorithm code
end=clock();
printf("time=%f\n",(end-start)/CLK_TCK);

start=clock();
DDA line algorithm code
end=clock();
printf("time=%f\n",(end-start)/CLK_TCK);

Also I'm getting t=0.164835 for both codes separately. Whereas DDA line algorithm should take more time. What is it that I’m doing wrong?
 
Physics news on Phys.org
Your times aren't granular enough for what you're trying to measure. The basic unit of the clock_t type is seconds, which is way too large for measuring operations that are happening at clock rates in the gigahertz range.