My measuring code looks like this (drawing its just simple triangle)
if(frames == 0)
{
gettimeofday(&tp, NULL);
start = tp.tv_usec;
}
drawGLScene();
swapBuffers();
++frames;
if(frames == 200)
{
gettimeofday(&tp, NULL);
stop = tp.tv_usec;
cout << "Time elapsed (ms): " << stop - start <<"FPS = " << 200 / ((stop - start) / 1000) << endl;
frames = 0;
deltas = 0;
start = 0;
stop = 0;
}
And i’m gettin strange output like
Time elapsed (ms): -379370FPS = 0
Time elapsed (ms): 623966FPS = 0
Time elapsed (ms): -383865FPS = 0
Time elapsed (ms): -376072FPS = 0
Time elapsed (ms): 620142FPS = 0
PS vars ‘start’ and ‘stop’ are declared as suseconds_t. what i am doing wrong ?
Hi
The tv_usec member counts milliseconds, but rolls back to 0 every second. You need to check the seconds as well:
gettimeofday (&tp, NULL);
sec0 = tp.tv_sec;
usec0 = tp.tv_usec;
and then after doing something
gettimeofday (&tp, NULL);
sec = tp.tv_sec;
usec = tp.tv_usec;
dusec = (sec - sec0) * 1000000 + (usec - usec0)
BTW, if you want something much more useful then FPS, have the GPU return how long parts of your algorithm takes,
// somewhere initialize your query object(s)
glGenQueries(1,&query);
Then when doing GPU stuff or drawing,
// handle result from previous frame
glGetQueryObjectiv(query,GL_QUERY_RESULT,&result);
// start query for new frame
glBeginQuery(GL_TIME_ELAPSED_EXT,query);
… // do something
// end query for new frame
glEndQuery(GL_TIME_ELAPSED_EXT);
system
Closed
4
This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.