Compare execution time in C language

Click For Summary
SUMMARY

The discussion focuses on comparing execution times for DDA and Bresenham's Line algorithms implemented in C. The user reports execution times of 0.164835 seconds for Bresenham's algorithm and 0 seconds for DDA, indicating a measurement issue. The primary conclusion is that the clock_t type's resolution is insufficient for accurately measuring the execution time of these algorithms, as it operates in seconds, which is too coarse for high-speed operations.

PREREQUISITES
  • Understanding of C programming language
  • Familiarity with clock_t data type and time measurement in C
  • Knowledge of DDA and Bresenham's Line algorithms
  • Basic concepts of algorithm performance analysis
NEXT STEPS
  • Research high-resolution timing methods in C, such as using chrono library in C++ or gettimeofday in C
  • Learn about performance profiling tools like gprof or Valgrind
  • Explore algorithm complexity analysis to understand expected execution times
  • Investigate the impact of compiler optimizations on execution time
USEFUL FOR

C programmers, computer science students, and software developers interested in performance optimization and algorithm analysis.

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.
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 1 ·
Replies
1
Views
11K
Replies
1
Views
4K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 2 ·
Replies
2
Views
1K
  • · Replies 21 ·
Replies
21
Views
4K
Replies
2
Views
2K
  • · Replies 12 ·
Replies
12
Views
3K
  • · Replies 5 ·
Replies
5
Views
4K