What's the best way to check how much free time I have between the end of my Update procedure and the next Draw event?

I want to keep a careful track of how much time my code is taking up.

  • \$\begingroup\$ Do you know when next Draw event is going to happen? Can you get current time within Update? What stops you from subtracting one from another and getting the result? \$\endgroup\$
    – Kromster
    Commented Jan 21, 2016 at 18:04
  • \$\begingroup\$ I haven't tried anything yet. I'm new to Monogame, I'm using VB and I'm not sure I have full control over the Monogame layer. So I thought I'd ask before losing 3 days trying things that don't work. \$\endgroup\$ Commented Jan 21, 2016 at 18:22
  • \$\begingroup\$ Having been in software development for many years I have become all too woefully aware that software timers are usually not very accurate. This is why I asked the question. \$\endgroup\$ Commented Jan 21, 2016 at 18:51
  • \$\begingroup\$ This looks like XY problem. What you really asking is "How do I get precise time"? \$\endgroup\$
    – Kromster
    Commented Jan 22, 2016 at 5:29

1 Answer 1


Use a timer with a decent resolution (such as QueryPerformanceCounter on Windows).

At the end of your update routine, query the timer and store the result somewhere. At the start of your draw routine, query the timer again and compare the result to the value from the end of the update routine.

That will tell you how much time elapsed between the two.

This seems like an unusual interval to measure, though; normally I'd think you'd want to measure the time taken from the start of update to the end of update, or the start of a draw to the end of a draw, and not the time between update and draw, during which (generally) not very much happens.

  • \$\begingroup\$ I want to track the free time so I can keep an eye on how much processing time is taken by all the pixel checking I'm going to have to do. If I get close to no-time-left I know I'm going to impact frame rate. Is it ok to check using GameTime or should I look lower level like the PerfCount you suggest? (Which I'd have to learn) \$\endgroup\$ Commented Jan 21, 2016 at 18:25
  • \$\begingroup\$ MonoGame's GameTime is probably fine for these crude sorts of measurements for now; I don't know what it uses under the hood but it might just be QPC based itself. If you're really interested in profiling, you should use a real profiler though. \$\endgroup\$
    – user1430
    Commented Jan 21, 2016 at 18:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .