A Thread’s Execution Times
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 GetTickCount64
function:
// 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. ...
Get Windows® via C/C++, Fifth Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.