I'm measuring the time between frames in a simple WPF animation. Perforator says the app performs at ~60fps, so I expected the time between frames to be ~16.6ms with little deviation.

    public MainWindow()
    {
    ...
        CompositionTarget.Rendering += Rendering;
    }

    List<long> FrameDurations = new List<long>();
    private long PreviousFrameTime = 0;
    private void Rendering(object o, EventArgs args)
    {
        FrameDurations.Add(DateTime.Now.Ticks - PreviousFrameTime);
        PreviousFrameTime = DateTime.Now.Ticks;
    }

Two things surprised me:

  • Time between frames is fairly irregular
  • Time between frames is ~8ms. I had expected that the monitor's refresh rate would set a lower bound on time between frames (ie. 60Hz = 16.6ms between each frame, and anything faster is pointless).

DefaultFrameRate

Y - Time between frames in ticks (10,000 ticks = 1ms)
X - Frame count

Possible confounding factors

  • Timer inaccuracy
  • If CompositionTarget.Rendering doesn't actually correlate to the drawing of a single frame

The project I'm using: SimpleWindow.zip

===Edit

Markus pointed out I could be using RenderingEventArgs.RenderingTime.Ticks instead of DateTime.Now.Ticks. I repeated the run and got very different results. The only difference is timing method:

DateTime.Now.Ticks

DefaultFrameRate

RenderingEventArgs.RenderingTime.Ticks

enter image description here

Data from RenderingEventArgs produced data much closer the expected 16.6ms/frame, and it is consistent.

Edit
Report