high resolution time function under windows platform?

Discussion in 'C++' started by wavelet, Aug 1, 2005.

  1. wavelet

    wavelet Guest

    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
    wavelet, Aug 1, 2005
    #1
    1. Advertising

  2. 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.
    Victor Bazarov, Aug 1, 2005
    #2
    1. Advertising

  3. "wavelet" <> wrote in message
    news:dcllcd$...
    > 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;


    }
    >
    >
    Bill Shortall, Aug 1, 2005
    #3
  4. 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.
    Tobias Blomkvist, Aug 1, 2005
    #4
  5. wavelet

    Guest


    > 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, 2005
    #5
  6. wavelet

    Maett Guest

    Maett, Aug 2, 2005
    #6
  7. wavelet

    Guest

    , Aug 2, 2005
    #7
  8. wavelet

    Maett Guest

    <> 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.lang.c /browse_frm/thread/d2311bd443c376b/a0c413f34baf1a7f

    >
    > 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
    Maett, Aug 2, 2005
    #8
  9. > 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.
    Marcin Kalicinski, Aug 4, 2005
    #9
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andrew FPGA
    Replies:
    0
    Views:
    955
    Andrew FPGA
    Sep 26, 2005
  2. Uwe Mayer

    high resolution time needed

    Uwe Mayer, Feb 21, 2005, in forum: Python
    Replies:
    1
    Views:
    363
    Diez B. Roggisch
    Feb 21, 2005
  3. John

    High resolution sleep (Linux)

    John, May 4, 2007, in forum: Python
    Replies:
    21
    Views:
    855
    Ian MacLure
    Jun 2, 2007
  4. Replies:
    11
    Views:
    567
  5. Agendum
    Replies:
    8
    Views:
    1,104
    Jonathan N. Little
    Mar 21, 2010
Loading...

Share This Page