mercredi 28 janvier 2015

Is chrono high resolution clock misbehaving?

I'm using the chrono::high_resolution_clock to do performance measurements. I'm running on Windows 7 using Visual Studio 2013 Express.


Here's the entire "get the time in nanoseconds" function.



/// @brief Get the current time in nanoseconds in some arbitrary epoch.
static uint64_t now()
{
auto point = std::chrono::high_resolution_clock::now();
std::chrono::nanoseconds duration = point.time_since_epoch();
return duration.count();
}


A typical test run takes between 5 and ten seconds. The test looks something like this:



auto before = now();
for(auto nLoop = 0; nLoop < AVeryBigNumber; ++nLoop)
{
perform the test function
}
auto after = now();
auto lapse = after - before;
auto nsecPerFunction = lapse/AVeryBigNumber;
std::cerr << AVeryBigNumber << " iterations in "
<< lapse << " nanoseconds is "
<< nsecPerFunction " nsec./func." << std::endl;


Most of the time it behaves exactly as expected and the results are plausible (the lapse matches wall clock time). Every now and the something goes wrong. The value returned by now() doesn't change so lapse and nsecPerFunction are zero even though the ran several seconds.


Once it goes wrong it stays wrong. The test continues to produce bogus results until I log out and back in, or sometimes until I restart the computer.


I would suspect a hardware problem except I've seen it on two separate machines now. Both are 8 core Intel I7 machines.



  • Question 1: Does the above code use std::chrono correctly?

  • Question 2: Is there a known error in Windows and/or VC12 (Visual studio 2013) that would explain this?

  • Question 3: Any suggestions on how to diagnose the problem -- or better yet how to fix it permanently?


Aucun commentaire:

Enregistrer un commentaire