Mail Archives: djgpp/1999/07/07/19:24:59
Young Fan wrote:
>
> Hi,
>
> Thanks for your help. I've been trying to solve this problem for a whole
> week. There are very few comments in the DGJPP include files, so I was
> wondering if you tell me how to use both the uclock and the timestamp
> counter. This is what I found for uclock in sys/time.h:
>
> #include <sys/types.h>
> typedef long long uclock_t;
> #define UCLOCKS_PER_SEC 1193180
> int gettimeofday(struct timeval *_tp, struct timezone *_tzp);
> unsigned long rawclock(void);
> int select(int _nfds, fd_set *_readfds, fd_set *_writefds, fd_set
> *_exceptfds, struct timeval *_timeout);
> int settimeofday(struct timeval *_tp, ...);
> uclock_t uclock(void);
The only one you need is `uclock'. Thus:
uclock_t start, end;
start = uclock();
/* stuff to be timed */
end = uclock();
printf("It took %.15f seconds\n", ((double)(end - start)) /
UCLOCKS_PER_SEC);
The cast to double is important to get resolution better than 1 second.
> Would I still run into problems with Windows about this if I restarted
> in MS-DOS mode?
I can't imagine that you would.
> If the uclock doesn't work, how would I use the CPU's timestamp counter?
Here is a function to read the counter.
inline unsigned long long rdtsc(void)
{
unsigned long long r;
asm("rdtsc" : "=A" (r));
return r;
}
You can use it like `uclock'. Just replace `uclock_t' with `unsigned
long long', `uclock' with `rdtsc', and `UCLOCKS_PER_SEC' with your CPU's
clock speed in hertz.
HTH
--
Nate Eldredge
nate AT cartsys DOT com
- Raw text -