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!

hi resolution timer questions 1

Status
Not open for further replies.

jsmokey

Technical User
Aug 19, 2005
10
0
0
US
hi, I would like to use a high resolution timer to time some disk accesses. I want to do this in a loop where i start the timer, do a random access of a file, stop the timer, add the number in nanoseconds to the running total for averaging later. The pseudocode looks like this

for i = 1 to 100
start timer
tell it where to go in diskspace
read a few characters
stop timer
add the time i got in this pass to the running total

next i

I know how to do everything except the timer. Ive never used a timer before and im not too fermilliar with c programming for linux or cygwin. Does anyone know how to set up the timer, what libraries i need, how to start it and stop it and how to save the time in some sort of variable? thanks in advance
 
There is the gettimeofday function which returns time with a precision of microseconds.
However, the accuracy is unspecified (it could just bump the microsecond count by 1000 every millisecond).

For a really fast and really accurate clock, then there is the rdtsc instruction for pentium users.

--
 
If you are running on solaris you can try The other option is to use traditional clock() function. It's obviously less accurate that the ones mentioned by Salem.
This is about clock()
Code:
clock_t start, finish;
double duration;
start=clock();
/* your loop */
finish=clock();
duration=(double)(finish -start)/CLOCKS_PER_SEC;
Also here are some links to similar topics.


Regards, Martin

(OS and comp.)
using Linux and gcc
 
Status
Not open for further replies.

Similar threads

  • Locked
  • Question
Replies
1
Views
31
Replies
3
Views
55
  • Locked
  • Question
Replies
9
Views
47

Part and Inventory Search

Sponsor

Back
Top