Time Measurement in Game Programming - My Article in ProgramistaMag
Warning! Some information on this page is older than 5 years now. I keep it for reference, but it probably doesn't reflect my current knowledge and beliefs.
Wed 02 Oct2013
In new issue 9/2013 (16) of Programista magazine there is my next article (in Polish) - "Pomiar czasu w programowaniu gier" (Time Measurement in Game Programming). This is an article about very specific subject, important in game development, as well as programming other real-time systems. Most books about game development mention the subject of time measurement, but usually go quickly to higher level like creating some timer class etc. This article focuses on lower level and gives solid theoretical background. It covers:
How to represent time? What unit and what "point 0" to choose? What's the difference between absolute time and time interval?
How to store time? What ranges and precisions are available in various types in C++? Why and when the floating-point precision matters? What data type to choose? (Spoiler: int64_t is good idea and double is not :)
How to read time? Standard C and C++ library, as well as Windows and Linux API provide functions that return current time, but differ in returned type, unit, precision and other properties. What does it mean if the function is monotonic? Which one to choose?
Sample code with implementation of GameTime class that encapsulates a time value.
A section about FPS (Frames Per Second): What does it really mean? What kinds of FPS we can define and how to measure it? When using FPS is good idea and when is it wrong?
Finally: What is fixed timestep and why is it a good practice? What is latency and why is it not entirely dependent on FPS?
Plus some other information... You can find the magazine e.g. in Empik stores, as well as subscribe for electronic or paper version.