Archived

This topic is now archived and is closed to further replies.

Fast Timer (C++)

This topic is 5040 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

All the subsystems in my engine are implemented as tasks running in a "micro-kernel", whose purpose is to schedule tasks based on priority. Since each task can be skipped (only be called every few frames) to maintain frame rate, I pass each task a float containing the number of seconds elapsed since the last time it was called. I''m worried that this may slow down my game a lot, since the timer function is called several times per task per frame to provide this functionality. My timer is implemented using Win32 QueryPerformanceCounter(), which provides the precision I''m looking for (accurate physics simulation doesn''t work well with a granularity of a hundred milliseconds), but I was wondering if there was another way to get the elapsed time from a constant point that is accurate, yet not too processor-intensive. * I know premature optimization is bad, but counting to 10k takes 0.332 seconds with a task/kernel, but 3.77E-05 within a while loop. That''s a large difference, to say the least.

Share this post


Link to post
Share on other sites
On most computers, using timeGetTime() can get you to a precision of 1ms... not as accurate as QueryPerformanceCounter() but I suspect it may be a little faster since you don''t have to worry about dividing by frequency or anything. It''s worth running some tests at least.

Be sure to call timeBeginPeriod(1) and timeEndPeriod(1) when you''re done to set the theoretical precision of the timeGetTime to 1ms.

Share this post


Link to post
Share on other sites