Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Using 'QueryPerformanceCounter()'?

SephirothSephiroth Fayetteville, NC, USAMember Posts: 1,035
Alright I am using the named function to time my main loop in my 3D engine, but I don't have a clue how to use the "LARGE_INTEGER" to get timing. Basically, I get the time the loop starts, then get the time it's done, then want to subtract the end from the start and store as a float to pass to my other classes so they know how far to move objects or do whatever each frame. Could somebody explain this to me?

-[italic][b][red]S[/red][purple]e[/purple][blue]p[/blue][green]h[/green][red]i[/red][purple]r[/purple][blue]o[/blue][green]t[/green][red]h[/red][/b][/italic]

Comments

  • pingpongpingpong Member Posts: 937
    [b][red]This message was edited by pingpong at 2005-8-5 14:7:13[/red][/b][hr]
    Hello Seph, see if this helps:
    [code]
    __int64 freq, start, end, diff;

    // start
    QueryPerformanceFrequency((LARGE_INTEGER*)&freq);
    QueryPerformanceCounter((LARGE_INTEGER*)&start);

    // code to measure
    Sleep(1234);

    // end
    QueryPerformanceCounter((LARGE_INTEGER*)&end);
    diff = ((end - start) * 1000) / freq;

    unsigned int milliseconds = (unsigned int)(diff & 0xffffffff);
    printf("It took %u ms
    ", milliseconds);
    [/code]
    Should show "1234 ms" give or take an ms or 2

    If this is what you need, you might want to wrap it in a class, and remember, you only need to query the frequency (which is dependant on your processor) once.

    : Alright I am using the named function to time my main loop in my 3D engine, but I don't have a clue how to use the "LARGE_INTEGER" to get timing. Basically, I get the time the loop starts, then get the time it's done, then want to subtract the end from the start and store as a float to pass to my other classes so they know how far to move objects or do whatever each frame. Could somebody explain this to me?
    :
    : -[italic][b][red]S[/red][purple]e[/purple][blue]p[/blue][green]h[/green][red]i[/red][purple]r[/purple][blue]o[/blue][green]t[/green][red]h[/red][/b][/italic]
    :



  • vastramnaikvastramnaik Member Posts: 1

    hi,
    i want to profile amr codec on windows platform. for that i used QueryPerformanceCounter() function ,but unable to get exact MCPS per 1 sec.
    in equation diff = ((end - start) * 1000) / freq;

    1. why the difference is multiplyed with 1000?
    2. what QueryPerformanceCounter() function returns?
    3. what is the formula for calculating Million Cycles Per Sec (MCPS) ?

    i will be thankful is somebody explain this to me.


    -Naik


    : [b][red]This message was edited by pingpong at 2005-8-5
    : 14:7:13[/red][/b][hr]
    : Hello Seph, see if this helps:
    : [code]:
    : __int64 freq, start, end, diff;
    :
    : // start
    : QueryPerformanceFrequency((LARGE_INTEGER*)&freq);
    : QueryPerformanceCounter((LARGE_INTEGER*)&start);
    :
    : // code to measure
    : Sleep(1234);
    :
    : // end
    : QueryPerformanceCounter((LARGE_INTEGER*)&end);
    : diff = ((end - start) * 1000) / freq;
    :
    : unsigned int milliseconds = (unsigned int)(diff & 0xffffffff);
    : printf("It took %u ms
    ", milliseconds);
    : [/code]:
    : Should show "1234 ms" give or take an ms or 2
    :
    : If this is what you need, you might want to wrap it in a class, and
    : remember, you only need to query the frequency (which is dependant
    : on your processor) once.
    :
    : : Alright I am using the named function to time my main loop in my 3D engine, but I don't have a clue how to use the "LARGE_INTEGER" to get timing. Basically, I get the time the loop starts, then get the time it's done, then want to subtract the end from the start and store as a float to pass to my other classes so they know how far to move objects or do whatever each frame. Could somebody explain this to me?
    : :
    : : -[italic][b][red]S[/red][purple]e[/purple][blue]p[/blue][green]h[/green][red]i[/red][purple]r[/purple][blue]o[/blue][green]t[/green][red]h[/red][/b][/italic]
    : :
    :
    :
    :
    :

  • SephirothSephiroth Fayetteville, NC, USAMember Posts: 1,035
    You do realize that this thread was from 2005, right?

    -[italic][b][red]S[/red][purple]e[/purple][blue]p[/blue][green]h[/green][red]i[/red][purple]r[/purple][blue]o[/blue][green]t[/green][red]h[/red][/b][/italic]
Sign In or Register to comment.