high resolution time function under windows platform?

W

wavelet

Hi,

I am searching one time function under windows2000
with Visual C++ environment. Is there function available
like gethrtime() in unix? Thx.


#include <sys/time.h>

main()
{
hrtime_t start, end;
int i, iters = 100;

start = gethrtime();
for (i = 0; i < iters; i++)
getpid();
end = gethrtime();
printf("Avg getpid() time = %lld nsec\n", (end - start) / iters);
}

RGS,
Wavelet
 
V

Victor Bazarov

wavelet said:
I am searching one time function under windows2000
with Visual C++ environment. Is there function available
like gethrtime() in unix? Thx.
[..]

And the reason you're asking here is...?

If you need a time function under Windows, ask in a newsgroup
for programming Windows.
 
B

Bill Shortall

wavelet said:
Hi,

I am searching one time function under windows2000
with Visual C++ environment. Is there function available
like gethrtime() in unix? Thx.


#include <sys/time.h>

main()
{
hrtime_t start, end;
int i, iters = 100;

start = gethrtime();
for (i = 0; i < iters; i++)
getpid();
end = gethrtime();
printf("Avg getpid() time = %lld nsec\n", (end - start) / iters);
}

RGS,
Wavelet

Hi wavellet,

Windows has a millisecond timer available if thats good enough It returns
a long. Its in <windows.h>
usage is something like
long tim;
tim = GetTickCount();
// put what you want to time in here
tim = GetTickCount() - tim;


}
 
T

Tobias Blomkvist

wavelet sade:
Hi,

I am searching one time function under windows2000
with Visual C++ environment. Is there function available
like gethrtime() in unix? Thx.

QueryPerformanceCounter
QueryPerformanceFrequency

Tobias
 
V

velthuijsen

Windows has a millisecond timer available if thats good enough It returns
a long. Its in <windows.h>
usage is something like
long tim;
tim = GetTickCount();
// put what you want to time in here
tim = GetTickCount() - tim;

One caveat here. The millsecond timers in Windows do not update every
millisecond. For windows since NT 3.1 the millisecond timers update
roughly every 16 milliseconds. The 95 famliy updates roughly every 55
milliseconds.
 
M

Maett

What is the point you were trying to make?

Sorry if that was unclear:
I just wanted to add that the Windows millisecond timer tick depends on
your hardware (whether it's 10 ms or roughly 16 ms).
You can even vary it on certain hardware types.

Maett
 
M

Marcin Kalicinski

I am searching one time function under windows2000
with Visual C++ environment. Is there function available
like gethrtime() in unix? Thx.

Try these:

QueryPerformanceCounter();

or

GetThreadTimes();

or the ultimate (80x86 only):

__asm __emit 0fh
__asm __emit 031h

And 64 bit result is in EDX:EAX. The unit is one cpu cycle.

cheers,
M.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,430
Messages
2,571,676
Members
48,796
Latest member
Greg L.

Latest Threads

Top