Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Timing a loop in microseconds 2

Status
Not open for further replies.

Disruptive

Programmer
Mar 8, 2005
40
0
0
GB
How can I introduce timing for a routine/loop in C, I seem to see so many conflicting and not working examples on the web. I can time in seconds but some of these processes are lasting less than a second so it does not help with my optimisation. Could some point to some useful code that will enable me to time my routines.

Thanks
 
> I seem to see so many conflicting and not working examples on the web.
That's because sub-second timing accuracy is heavily dependent on your OS and compiler (which you continue to omit from any of your posts).

State your OS / Compiler / processor, and be specific about it. "Windows", "Microsoft", "Intel" just won't cut it.

--
 
You can use clock() function from <time.h>
Code:
clock_t start, finish;
double duration;
start=clock();
/* your loop */
finish=clock();
duration=(double)(finish -start)/CLOCKS_PER_SEC;
If someone knows other (maybe more accurate) way to measure loop execution time, I will appreciate it cause I am also looking for such fuction :)

Martin
 
Just to follow up, I managed to play around and replace the fmod with a floor function with modifications. This seems to run a little quicker. I guess it is much easier to calculate than fmod or so it would seem!

Thanks again guys!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top