By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,130 Members | 1,365 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,130 IT Pros & Developers. It's quick & easy.

high resolution time function under windows platform?

P: n/a
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
Aug 1 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
wavelet wrote:
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.
Aug 1 '05 #2

P: n/a

"wavelet" <li***@lucent.com> wrote in message
news:dc********@netnews.net.lucent.com...
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;
}

Aug 1 '05 #3

P: n/a
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
--
IMPORTANT: The contents of this email and attachments are confidential
and may be subject to legal privilege and/or protected by copyright.
Copying or communicating any part of it to others is prohibited and may
be unlawful.
Aug 1 '05 #4

P: n/a
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.

Aug 2 '05 #5

P: n/a
ve*********@hotmail.com <ve*********@hotmail.com> wrote:

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.


You might want to look at
http://groups.google.ch/group/comp.l...c413f34baf1a7f

Greets
Maett
Aug 2 '05 #6

P: n/a
> You might want to look at
http://groups.google.ch/group/comp.l...c413f34baf1a7f


What is the point you were trying to make?

Aug 2 '05 #7

P: n/a
ve*********@hotmail.com <ve*********@hotmail.com> wrote:
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.
You might want to look at
http://groups.google.ch/group/comp.l...c413f34baf1a7f


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
Aug 2 '05 #8

P: n/a
> 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.


Aug 4 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.