Mail Archives: djgpp/2001/07/28/23:15:06
Seems to work on my computer, too. I have a 1Ghz. Athlon Processor
running Win98se and it shows 1000+/- about 3 Mhz . I modified the
program a little to make it average 100 results and it averages at
1000Mhz, exactly where it sould be.
-Ian-
Daniel Friberg wrote:
> Thanks for all the replies! This is what I came up with and it seems
> too work fine on my K6-2 computers.
>
> #include <stdio.h>
> #include <time.h>
>
> int main()
> {
> unsigned long val1, val2,speed;
> unsigned long tm1,tm2,i ;
> double time;
>
> tm1 = uclock();
> asm
> (
> "rdtsc\n
> movl %%eax, %0"
> : "=g" (val1)
> : /* no inputs */
> : "ax", "dx"
> );
> for(i=0;i<100000;i++);
> tm2 = uclock();
> asm
> (
> "rdtsc\n
> movl %%eax, %0"
> : "=g" (val2)
> : /* no inputs */
> : "ax", "dx"
> );
>
> time = (double) (tm2 - tm1) / UCLOCKS_PER_SEC;
> speed = (val2-val1)/time/1000000;
>
> printf("Time elapsed: %f seconds.\n",time);
> printf("Cycles executed: %d.\n",val2-val1);
> printf("Calculated speed: %dMHz.\n",speed);
>
> return 0;
> }
>
> //Daniel
- Raw text -