From: Young Fan Newsgroups: comp.os.msdos.djgpp Subject: Re: Timing Date: Thu, 08 Jul 1999 09:18:54 -0400 Organization: Nortel Lines: 40 Message-ID: <3784A53E.EB898F54@hotmail.com> References: <377CC7E6 DOT EB82B079 AT hotmail DOT com> <3780B0B3 DOT CE964094 AT hotmail DOT com> <3783E08C DOT 2BA33F77 AT cartsys DOT com> NNTP-Posting-Host: pwdld0av.ca.nortel.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Mailer: Mozilla 4.03 [en] (Win95; I) To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com 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