0

私はOpenGL、Qt、C++を使って3Dモデル表示プログラムを書いています.しかし、私は何か奇妙なことを発見しました.それは、リリースモードバージョンのFPS(フレーム/秒)がデバッグモードバージョンよりも低いです.今、私は彼らのFPSを投稿します:

左がデバッグモード版、右がリリースモード版です。

ここに画像の説明を入力 ここに画像の説明を入力

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;
    }
}

なぜこれが起こるのだろうか?リリースモードはデバッグモードよりも速くすべきではないのだろうか?誰かが理由を教えてくれるだろうか?

4

1 に答える 1

1

これによると、 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;
}
于 2012-07-18T16:15:55.663 に答える