Skip to main content
GameDev.net gamedev.net
🔒 Locked

Timing Methods and Functions

Started by AndyTang Dec 11, 2002 at 6:41 PM 0 replies 500+ views
Original Post
AndyTang
AndyTang
The title says it all really. Is there a way to time functions and methods? Thanks
botman
botman
QueryPerformanceCounter()?...
#include <windows.h>
#include <stdio.h>

void main(void)
{
long x, y;
LARGE_INTEGER PerfFreq;
LARGE_INTEGER PerfCountStart, PerfCountEnd, PerfDiff;
float interval;

QueryPerformanceFrequency(&PerfFreq);

if (PerfFreq.QuadPart == 0)
{
printf("Your hardware doesn''t support High Resolution Perfomance Counters!\n");
return;
}

PerfFreq.QuadPart = PerfFreq.QuadPart / 1000; // ticks per millisecond

QueryPerformanceCounter(&PerfCountStart);

y = 0;
for (x=0; x < 1000000L; x++)
y = y + x;

QueryPerformanceCounter(&PerfCountEnd);

PerfDiff.QuadPart = PerfCountEnd.QuadPart - PerfCountStart.QuadPart;

interval = (float)PerfDiff.QuadPart / (float)PerfFreq.QuadPart;

printf("The loop took %7.4f milliseconds\n", interval);
}

botman

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.