Compare execution time in C language

  • Thread starter Vagrant
  • Start date
  • #1
195
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?
 

Answers and Replies

  • #2
34,005
5,660
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.
 

Related Threads on Compare execution time in C language

  • Last Post
Replies
2
Views
458
  • Last Post
Replies
1
Views
698
Replies
1
Views
7K
Replies
21
Views
2K
  • Last Post
Replies
5
Views
1K
  • Last Post
Replies
6
Views
2K
  • Last Post
Replies
13
Views
2K
  • Last Post
Replies
0
Views
4K
  • Last Post
Replies
2
Views
1K
Replies
2
Views
9K
Top