Fast Timer (C++)
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.
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.
Be sure to call timeBeginPeriod(1) and timeEndPeriod(1) when you''re done to set the theoretical precision of the timeGetTime to 1ms.
> All the subsystems in my engine are implemented as tasks running in a "micro-kernel"
Yikes!
Timing Pitfalls on the PC, and Solutions.
// edit: whee, nice effect if you don't close an anchor tag
[edited by - Jan Wassenberg on February 22, 2004 8:50:45 PM]
Yikes!
Timing Pitfalls on the PC, and Solutions.
// edit: whee, nice effect if you don't close an anchor tag
[edited by - Jan Wassenberg on February 22, 2004 8:50:45 PM]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement