开发者

Windows Form, Getting FPS?

I'm writing a windows application which is displaying real time data on a map. Is there a simple way to get the FPS (Frames Per Second)?

Than开发者_如何学Pythonks, couldn't find much on google. This is C#, .NET 4.0.


Calculating FPS may be something as simple as this (if precision is not of uttermost importance):

DateTime _lastCheckTime = DateTime.Now;
long _frameCount = 0;

// called whenever a map is updated
void OnMapUpdated()
{
    Interlocked.Increment(ref _frameCount);
}

// called every once in a while
double GetFps()
{
    double secondsElapsed = (DateTime.Now - _lastCheckTime).TotalSeconds;
    long count = Interlocked.Exchange(ref _frameCount, 0);
    double fps = count / secondsElapsed;
    _lastCheckTime = DateTime.Now;
    return fps;
}

Set an update timer to call GetFps() every second to get the value. Note that there should be no concurrent calls to this method, since every call resets counters and start time.


How are you drawing your map? It all depends on what technology you are using... My recomendations go for managed DirectX if you are doing graphic intensive work.

Try to get more info here: http://www.programmersheaven.com/2/time-fps

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜