OON: RE: oon-digest V1 #31

From: Telford Berkey (telford_berkey@qualia-computing.com)
Date: Mon Feb 01 1999 - 10:21:07 EST


The following code works for Intel CPU's only. It must be a Pentium or higher
CPU. There is an instruction called Read Time Stamp Counter (RDTSC).
RDTSC is a 64 bit counter that is initialized to zero when the CPU is
powered on and increments by one, every clock tick thereafter. The following
function works in Visual C++ 5.0 sp3. This should work in VC++ 6.0, but
I haven't tried it. Although VC++ 6.0 might understand the RDTSC opcodes.
VC++ 5.0 doesn't understand the RDTSC opcodes, so the first task is to
emit these in the inline assembly block for the compiler. Then read the
low and high 32-bit words from the counter. Since you should know
the clock speed of your CPU(s), you now have a counter with resolution
close to it's clock rate.

  double
  GetCPUCount( unsigned int &low_word, unsigned int &high_word )
  {
                _asm
                {
                        _emit 0x0f ; rdtsc
                        _emit 0x31
                        mov high_word,edx
                        mov low_word,eax
                }
    
    return (todouble(low_word, high_word));
  }

Check out the Intel's online manuals at "developer.intel.com" for more
details. Let me know if you need more details.

-----------------------------------------------------------------------------------------------

Telford Berkey, Software Developer

Qualia Computing, Inc. Voice: (937) 431-1464
2372 Lakeview Dr, Suite G Fax: (937) 431-1465
Beavercreek, OH 45431 Email: telford_berkey@qualia-computing.com

"Committed to developing the best breast cancer
detection system for the most women as soon as possible"

oon-digest Sunday, 31 January 1999 Volume 01 : Number 031

----------------------------------------------------------------------

From: Roscoe A Bartlett <roscoe@andrew.cmu.edu>
Date: Sat, 16 Jan 1999 16:47:18 -0500 (EST)
Subject: OON: Precise timer function in WIn95/NT?

Does anyone know of a precise timer function to be used in Windows 95 with
Microsoft Visual C++ 6.0? The provided standard library provides timing
as clock() / CLOCKS_PER_SEC but CLOCKS_PER_SEC is only 1000. So
theoretically this only gives a precision of 0.001 sec. However from
tests the accuracy is more like 0.05 sec (20 times worse). I know that
in some implementations CLOCKS_PER_SEC = 1000000 or a posible 1.0e-6 sec
precision.

Does anyone know of a way to get better timing precision in MS VC++ 6.0 on
Win95? Perhaps there is a third party library. I need these timings for
my research.

 --------------------------------------
| Roscoe Bartlett |
| Ph.D. student |
| Department of Chemical Engineering |
| Carnegie Mellon University |
| email: roscoe@andrew.cmu.edu |
 --------------------------------------

------------------------------

From: Chris Hecker <checker@d6.com>
Date: Sat, 16 Jan 1999 21:05:53 -0800
Subject: Re: OON: Precise timer function in WIn95/NT?

>Does anyone know of a way to get better timing precision in MS VC++ 6.0 on
>Win95? Perhaps there is a third party library. I need these timings for
>my research.

Look at QueryPerformanceCounter and QueryPerformanceFrequency. It's around
microsecond accuracy.

Chris

--------------------- Object Oriented Numerics List --------------------------
* To subscribe/unsubscribe: mail to majordomo@oonumerics.org, with
"subscribe oon-list" or "unsubscribe oon-list" in the body of the message
* Digest format available: "subscribe oon-digest"
* OON Web page: http://oonumerics.org/oon/



This archive was generated by hypermail 2b29 : Wed Feb 20 2002 - 03:20:07 EST