|
Boost Users : |
Subject: [Boost-users] [Chrono] Negative real time
From: Wilfried Kirschenmann (wilfried.kirschenmann_at_[hidden])
Date: 2012-05-22 12:55:56
Dear chrono maintainer team,
Using the following example :
int main(int argc, char **argv)
{
boost::chrono::process_real_cpu_clock::time_point start =
boost::chrono::process_real_cpu_clock::now();
for ( long i = 0; i < 1000; ++i ) std::sqrt( 123.456L ); // burn
some time
Sleep(10000); //idle some time
boost::chrono::process_real_cpu_clock::time_point end =
boost::chrono::process_real_cpu_clock::now();
std::cout << end << std::endl;
boost::chrono::process_real_cpu_clock::duration elapsed = (end -
start);
std::cout << "took real : " << elapsed << "nanoseconds\n";
return 0;
}
I obtain negative times.
I run boost 1.49 win32 on Windows 7 x64 with Visual studio 2010.
Studying the behavior of the timer, I think that the error is one of these :
- process_real_cpu_clock::now() only stores the current time in a 32 bit
integer instead of a 64 bit integer
- time_points only prints the 32 lowest bits.
I came to this conclusion by observing the results printed before they got
negatives (printing in the loop with the sqrt): 2019000000 nanoseconds is
the last value printed before getting negative.
Is there any mistake in my way of using this chronometer ?
Do you have a workaround ?
Thank you for your help !
Wilfried K.
-----
Cordialement,
Wilfried Kirschenmann
"An expert is a person who has made all the mistakes that can be made in a
very narrow field."*
*Niels Bohr - *Danish physicist (1885 - 1962)*
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net