Compare execution time in C language

AI Thread Summary
The discussion focuses on comparing execution times for DDA and Bresenham's Line algorithms in C. The user reports obtaining a time of 0.164835 seconds for Bresenham's algorithm and 0 seconds for DDA, which is unexpected since DDA should take longer. The issue arises from using the clock_t type, which has a resolution too coarse for measuring such quick operations. To achieve more accurate timing, a higher-resolution timer should be used, such as the high-resolution clock available in C. Accurate timing is crucial for performance comparisons in algorithm execution.
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.
 
Back
Top