Mail Archives: cygwin/1997/08/04/10:39:38
On Fri, 25 Jul 1997, Joerg Lepler wrote:
>
> Hi,
>
> Does anyone know about such clock functions for the win32 environment?
>
There is the (undocumented) function NtQueryPerformanceCounter which
returns a 64 bit counter value and the frequency of the counter update.
I use this function on a Everex Dual Pentium Pro with 200 MHz. On this
computer the call to this function takes about 14 microseconds and the
counter has a resolution of 5 ns (= 1 / 200 MHz).
On single processor machines calls may take significantly longer and
the resolution is much less, so your mileage may vary. See the recent
discussion on comp.os.ms-windows.programmer.nt.kernel-mode for details.
I attach an example how to use this function.
BTW: Which functions did you use on SUN and SGI ?
HTH
Gerhard G. Thallinger
Vexcel Imaging GmbH
---------------------------Start of program profile.c -------------------------
/*
* This code is supplied 'as is', no warranty whatsoever implied.
* Use at your own risk.
*/
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
typedef LONG NTSTATUS;
typedef NTSTATUS WINBASEAPI (WINAPI *NtQPC)(LARGE_INTEGER* pCounter,
LARGE_INTEGER* pFrequency);
#undef __FUNC__
#define __FUNC__ "GetFuncAddress()"
NtQPC GetFuncAddress()
{
NtQPC pTemp = NULL;
NTSTATUS result = 0;
int loadLib = 0;
HMODULE hNtDll = NULL;
hNtDll = GetModuleHandle("ntdll");
if (hNtDll == NULL) {
hNtDll = LoadLibrary("ntdll");
loadLib = 1;
}
if (hNtDll != NULL) {
pTemp = (NtQPC) GetProcAddress(hNtDll, "NtQueryPerformanceCounter");
if (loadLib != 0) {
FreeLibrary(hNtDll);
}
}
return(pTemp);
}
#undef __FUNC__
#define __FUNC__ "main()"
main(int argc, char* argv[])
{
NTSTATUS result = 0;
int iLoop;
LARGE_INTEGER llCount;
LARGE_INTEGER llFrequency;
NtQPC NtQueryPerformanceCounter = NULL;
NtQueryPerformanceCounter = GetFuncAddress();
if (NtQueryPerformanceCounter != NULL) {
for (iLoop = 0; iLoop < 1000000;iLoop++) {
result = NtQueryPerformanceCounter(&llCount,&llFrequency);
}
} else {
fprintf(stderr,"Could not determine function address");
}
return(0);
}
---------------------------End of program profile.c -------------------------
-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request AT cygnus DOT com" with one line of text: "help".
- Raw text -