2012-07-17 86 views
0

我使用OpenGL,Qt,C++编写了3D模型显示程序,但是我发现了一些奇怪的东西,即发布模式版本中的FPS(每秒帧数)低于调试模式版本。现在我张贴他们的FPS:FPS:发布模式版本低于调试

左边是调试模式版本,右边是发行模式版本:

enter image description here enter image description here

我用它来计算FPS功能是

void displayFPS() 
{ 
    static float framesPerSecond = 0.0f;  // This will store our fps 
    static float lastTime = 0.0f;  // This will hold the time from the last frame 
    float currentTime = GetTickCount() * 0.001f;  
    ++framesPerSecond; 
    if(currentTime - lastTime > 1.0f) 
    { 
     framesPerSecond/=currentTime - lastTime; 
     char strFrameRate[256]; 
     lastTime = currentTime; 
     sprintf_s(strFrameRate,256, "FPS : %f", framesPerSecond); 
     cout << strFrameRate << endl; 
     framesPerSecond = 0; 
    } 
} 

我不知道这怎么会发生?不应该释放模式比调试模式更快吗?有人可以告诉我为什么吗?

+0

我觉得很难从给出的信息中分辨出来。 displayFPS()函数应该可以正常工作。 btw ..为什么你使用sprintf_s写入fps到控制台?而不是'cout <<“FPS:”<< framesPerSecond << endl;' – Dirk 2012-07-18 07:58:05

+0

有时,vsync会导致有趣的效果。你有没有尝试禁用vsync?对于Nvidia GPU,您可以在Nvidia控制面板 - >管理3D设置 - >垂直同步:强制关闭。 – kroneml 2012-07-18 12:51:13

回答

1

根据this的准确性GetTickCount()比一毫秒差得多。它甚至可能像55毫秒一样糟糕!使用更可靠的方法来测量时间间隔,如下所示:

#include <windows.h> 
#include <cstdint> 

typedef std::int64_t int64; 

// get duration of a single "clock" in microseconds 
double 
get_clock_duration() 
{ 
    LARGE_INTEGER f; 
    QueryPerformanceFrequency(&f); 
    return 1000000.0/double(f.QuadPart); 
} 

// get number of elapsed clocks from program start 
int64 
clocks() 
{ 
    LARGE_INTEGER t; 
    QueryPerformanceCounter(&t); 
    return t.QuadPart; 
} 

// convert a duration in clocks to a duration in milliseconds 
double 
milliseconds(int64 t) 
{ 
    return get_clock_duration() * double(t) * 0.001; 
}