Sometimes you want to time how long it takes a thread to perform a particular task. What many people do is write code similar to the following, taking advantage of the new
// Get the current time (start time). ULONGLONG qwStartTime = GetTickCount64(); // Perform complex algorithm here. // Subtract start time from current time to get duration. ULONGLONG qwElapsedTime = GetTickCount64() - qwStartTime;
This code makes a simple assumption: it won’t be interrupted. However, in a preemptive operating system, you never know when your thread will be scheduled CPU time. When CPU time is taken away from your thread, it becomes more difficult to time how long it takes your thread to perform various tasks. ...