| www.delorie.com/archives/browse.cgi | search |
| From: | kallekula60 AT hotmail DOT com (Daniel Friberg) |
| Newsgroups: | comp.os.msdos.djgpp |
| Subject: | Re: Cpu speed detection using DJGPP? |
| Date: | 25 Jul 2001 00:47:26 -0700 |
| Organization: | http://groups.google.com/ |
| Lines: | 44 |
| Message-ID: | <458df9bf.0107242347.5725a1a0@posting.google.com> |
| References: | <68C4CF842BD2D411AC1600902740B6DA02CDC45E AT mcoexc02 DOT mlm DOT maxtor DOT com> |
| NNTP-Posting-Host: | 212.181.169.243 |
| X-Trace: | posting.google.com 996047246 23077 127.0.0.1 (25 Jul 2001 07:47:26 GMT) |
| X-Complaints-To: | groups-support AT google DOT com |
| NNTP-Posting-Date: | 25 Jul 2001 07:47:26 GMT |
| To: | djgpp AT delorie DOT com |
| DJ-Gateway: | from newsgroup comp.os.msdos.djgpp |
| Reply-To: | djgpp AT delorie DOT com |
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
| webmaster | delorie software privacy |
| Copyright © 2019 by DJ Delorie | Updated Jul 2019 |