How do I display Frames Per Second?

The subject says it all; how do I see what FPS my app is getting DirectX must be stashing that info somewhere!


Answer this question

How do I display Frames Per Second?

  • BusmasterJones

    Does C# have an equivalent method to System.getNanoTime() in Java That would make life alot easier...

  • James Grant

    Have a look at the following sample... Call the CalculateFrameRate each time you render to the device, and either display it to the device in code or change you forms title text to display it ie. thisform1.title.txt = CalculateFrameRate().ToString();

    using System;
    using System.Collections.Generic;
    using System.Text;

    namespace VirtualRealm.Mdx.Common
    {
    public class Utility
    {
    #region Basic Frame Counter

    private static int lastTick;
    private static int lastFrameRate;
    private static int frameRate;

    public static int CalculateFrameRate()
    {
    if (System.Environment.TickCount - lastTick >= 1000)
    {
    lastFrameRate = frameRate;
    frameRate = 0;
    lastTick = System.Environment.TickCount;
    }
    frameRate++;
    return lastFrameRate;
    }
    #endregion

    }
    }



  • Flaatten

    Every example I've seen requires working it out by using a timer and counting how many times a second the screen gets refreshed.

    But it's possible that it's sitting in there also, it's been a while since I did DX.



  • pravin333

    Environment.TickCount is probably what you are looking for.


  • t_girl

    Cool! Thanks for the code.

  • How do I display Frames Per Second?