title: How do i display/show FPS on screen?
body: <p>I have this code sample i need to find how to show/display the frames per second on the screen. Tried to use the class but its not working good im not sure how to use it.</p>
  
  <pre><code>protected override void Initialize()
  {
      base.Initialize();
  
      fpsm = new FpsMonitor();
      fpsm.Update();
      fpsm.Draw(spriteBatch, fonts, new Vector2(5,5), Color.Red);
  
  }
  
  protected override void Update(GameTime gameTime)
  {
      // Allows the game to exit
      if (GamePad.GetState(PlayerIndex.One).Buttons.Back ==
          ButtonState.Pressed)
          this.Exit();
  
      modelRotation += (float)gameTime.ElapsedGameTime.TotalMilliseconds *
          MathHelper.ToRadians(0.1f);
  
      base.Update(gameTime);
  }
  
  protected override void Draw(GameTime gameTime)
  {
      graphics.GraphicsDevice.Clear(Color.CornflowerBlue);
  
      // Copy any parent transforms.
      Matrix[] transforms = new Matrix[myModel.Bones.Count];
      myModel.CopyAbsoluteBoneTransformsTo(transforms);
  
      // Draw the model. A model can have multiple meshes, so loop.
      foreach (ModelMesh mesh in myModel.Meshes)
      {
          // This is where the mesh orientation is set, as well 
          // as our camera and projection.
          foreach (BasicEffect effect in mesh.Effects)
          {
              effect.EnableDefaultLighting();
              effect.World = transforms[mesh.ParentBone.Index] *
                  Matrix.CreateRotationY(modelRotation)
                  * Matrix.CreateTranslation(modelPosition);
              effect.View = Matrix.CreateLookAt(cameraPosition,
                  Vector3.Zero, Vector3.Up);
              effect.Projection = Matrix.CreatePerspectiveFieldOfView(
                  MathHelper.ToRadians(45.0f), aspectRatio,
                  1.0f, 10000.0f);
          }
          // Draw the mesh, using the effects set above.
          mesh.Draw();
      }
      base.Draw(gameTime);
  }
  </code></pre>
  
  <p>And the FPS class:</p>
  
  <pre><code>public class FpsMonitor
  {
      public float Value { get; private set; }
      public TimeSpan Sample { get; set; }
      private Stopwatch sw;
      private int Frames;
      public FpsMonitor()
      {
          this.Sample = TimeSpan.FromSeconds(1);
          this.Value = 0;
          this.Frames = 0;
          this.sw = Stopwatch.StartNew();
      }
      public void Update()
      {
          if (sw.Elapsed &gt; Sample)
          {
              this.Value = (float)(Frames / sw.Elapsed.TotalSeconds);
              this.sw.Reset();
              this.sw.Start();
              this.Frames = 0;
          }
      }
      public void Draw(SpriteBatch SpriteBatch, SpriteFont Font, Vector2 Location, Color Color)
      {
          this.Frames++;
          SpriteBatch.DrawString(Font, "FPS: " + this.Value.ToString(), Location, Color);
      }
  }
  </code></pre>
  
  <p>I tried in the Game1.cs to use it in the constructor:</p>
  
  <pre><code>fpsm = new FpsMonitor();
  fpsm.Update();
  fpsm.Draw(spriteBatch, fonts, new Vector2(5,5), Color.Red);
  </code></pre>
  
  <p>But thats not how to use it.
  How do i use it and where in my code ?</p>