Re: Optimizing for speed (QueryPerformanceCounter)

New Message Reply About this list Date view Thread view Subject view Author view

David Honig (honig@otc.net)
Wed, 18 Feb 1998 10:09:40 -0800


At 12:39 AM 2/19/98 +1000, Eric Young wrote:
>
>On Tue, 17 Feb 1998, Chuck McManis wrote:
>> VC++5 on a Win95 platform and what I'd like is something like :
>>
>> long long t1, t2;
>> t1 = snap_time(); /* time in nSecs */
>> ... do something ...
>> t2 = snap_time();
>> printf("This run took %ld nS\n", (long)(t2 - t1));
>>
>
>Timing of this type of thing can be done at a cycle level via the following
>function

I have used this with the Win32 API in with MS VisC++ 4.2:

#define BIGMEASURE 1000000
#include <windows.h>

    LARGE_INTEGER ticks1,
      ticks2,
      tickfreq;
    int duration;
    float realtime,
      hertz;

    QueryPerformanceFrequency( &tickfreq );
       printf( "Ticks are %d %d per sec\n", tickfreq.HighPart,
tickfreq.LowPart );
       hertz = 1.0 / tickfreq.LowPart;

                   
        QueryPerformanceCounter( &ticks1 );
                // work
        QueryPerformanceCounter( &ticks2 );

        duration = ticks2.LowPart - ticks1.LowPart;
        realtime = duration * hertz;

        // i = number of bytes processed
        printf( "For %6d byte sample: %6d ticks %6f seconds %6e by/sec\n",
i, duration, realtime, i/realtime );

------------------------------------------------------------
      David Honig Orbit Technology
     honig@otc.net Intaanetto Jigyoubu

        Has Nike hired Monica to endorse kneepads yet?

        


New Message Reply About this list Date view Thread view Subject view Author view

 
All trademarks and copyrights are the property of their respective owners.

Other Directory Sites: SeekWonder | Directory Owners Forum

The following archive was created by hippie-mail 7.98617-22 on Fri Aug 21 1998 - 17:14:56 ADT