0
\$\begingroup\$

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.

\$\endgroup\$
  • \$\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 says support Monica Jan 21 '16 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\$ – MuntyScruntFundle Jan 21 '16 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\$ – MuntyScruntFundle Jan 21 '16 at 18:51
  • \$\begingroup\$ This looks like XY problem. What you really asking is "How do I get precise time"? \$\endgroup\$ – Kromster says support Monica Jan 22 '16 at 5:29
1
\$\begingroup\$

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.

\$\endgroup\$
  • \$\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\$ – MuntyScruntFundle Jan 21 '16 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 Jan 21 '16 at 18:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.