
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)*

Le 22/05/12 18:55, Wilfried Kirschenmann a écrit :
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
I don't know from where are you getting this conclusion. process_real_cpu_clock is using boost::int_least64_t, as representation. typedef duration<boost::int_least64_t, nano> nanoseconds; // at least 64 bits needed class BOOST_CHRONO_DECL process_real_cpu_clock { public: typedef nanoseconds duration; typedef duration::rep rep; typedef duration::period period; typedef chrono::time_point<process_real_cpu_clock> time_point; BOOST_STATIC_CONSTEXPR bool is_steady = true; static BOOST_CHRONO_INLINE time_point now() BOOST_NOEXCEPT; #if !defined BOOST_CHRONO_DONT_PROVIDE_HYBRID_ERROR_HANDLING static BOOST_CHRONO_INLINE time_point now(system::error_code & ec ); #endif };
- 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 <tel:2019000000> nanoseconds is the last value printed before getting negative.
I guess that you have included chrono_io.hpp. Could you confim this? If not, you will need to get the number of nanoseconds using count() std::cout << "took real : " << elapsed.count() << "nanoseconds\n"; If you have included it, the output should contain nanoseconds twice. E.g. 2383000 nanoseconds since process start-up took real : 37000 nanosecondsnanoseconds
Is there any mistake in my way of using this chronometer ?
It depends of whether you have included chrono_io.hpp or not. If not, could you post the complete program? HTH, Vicente

On Tue, May 22, 2012 at 9:41 PM, Vicente J. Botet Escriba < vicente.botet@wanadoo.fr> wrote:
Le 22/05/12 18:55, Wilfried Kirschenmann a écrit :
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
I don't know from where are you getting this conclusion. process_real_cpu_clock is using boost::int_least64_t, as representation.
typedef duration<boost::int_least64_t, nano> nanoseconds; // at least 64 bits needed class BOOST_CHRONO_DECL process_real_cpu_clock { public: typedef nanoseconds duration; typedef duration::rep rep; typedef duration::period period; typedef chrono::time_point<process_real_cpu_clock> time_point; BOOST_STATIC_CONSTEXPR bool is_steady = true;
static BOOST_CHRONO_INLINE time_point now() BOOST_NOEXCEPT; #if !defined BOOST_CHRONO_DONT_PROVIDE_HYBRID_ERROR_HANDLING static BOOST_CHRONO_INLINE time_point now(system::error_code & ec ); #endif
};
From the fact that it behaves as if there were a 32bit overflow. Which is in fact the case : https://svn.boost.org/trac/boost/ticket/6361 The problem is fixed in 1.50 and I no longer get negative times.
Wilfried K.

Le 23/05/12 09:39, Wilfried Kirschenmann a écrit :
On Tue, May 22, 2012 at 9:41 PM, Vicente J. Botet Escriba <vicente.botet@wanadoo.fr <mailto:vicente.botet@wanadoo.fr>> wrote:
Le 22/05/12 18:55, Wilfried Kirschenmann a écrit :
Dear chrono maintainer team,
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
I don't know from where are you getting this conclusion. process_real_cpu_clock is using boost::int_least64_t, as representation.
typedef duration<boost::int_least64_t, nano> nanoseconds; // at least 64 bits needed class BOOST_CHRONO_DECL process_real_cpu_clock { public: typedef nanoseconds duration; typedef duration::rep rep; typedef duration::period period; typedef chrono::time_point<process_real_cpu_clock> time_point; BOOST_STATIC_CONSTEXPR bool is_steady = true;
static BOOST_CHRONO_INLINE time_point now() BOOST_NOEXCEPT; #if !defined BOOST_CHRONO_DONT_PROVIDE_HYBRID_ERROR_HANDLING static BOOST_CHRONO_INLINE time_point now(system::error_code & ec ); #endif
};
From the fact that it behaves as if there were a 32bit overflow. Which is in fact the case : https://svn.boost.org/trac/boost/ticket/6361 The problem is fixed in 1.50 and I no longer get negative times.
Oh my bad, I forget this issue and I was locking on the trunk. Glad to see that you will get a solution with 1.50 :) Best, Vicente
participants (2)
-
Vicente J. Botet Escriba
-
Wilfried Kirschenmann