Mail Archives: djgpp/1999/07/08/19:35:16
Thanks a lot. I tried uclock, and it works beautifully when I restart in
MS-DOS mode.
Nate Eldredge wrote:
> 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 -