History:
FPS Counter
FPS Counter
Relatively accurate counting of cycles per second (Frames Per Second). Suitable for variable FPS in applications and especially in games.
Code
#include <windows.h>
#include <map>
#include <queue>
ULONGLONG resolution = 1000000, lastTime = 0, frequency = 1;
double lowId = 1;
std::queue<double> usedIds;
std::map<double, ULONGLONG> markers;
/*INIT*/
double Init()
{
if (QueryPerformanceFrequency((LARGE_INTEGER *)&frequency) && QueryPerformanceCounter((LARGE_INTEGER*)&lastTime)) {
return 0.0;
}
else {
return -1.0;
}
}
/*FPS*/
double FPS()
{
ULONGLONG now, lt;
if (QueryPerformanceCounter((LARGE_INTEGER*)&now)) {
lt = lastTime;
lastTime = now;
return (double)1000000/((now - lt)*resolution/frequency);
}
else {
return -1.0;
}
}
int main(int argc, char* argv[])
{
Init();
while(1)
{
printf(">%f<\n", (float)FPS() );
Sleep(12);
}
return 0;
}Code.Tode.cz by Henry - 2014
Facebook
YouTube
Joudove