Boost logo

Boost Users :

From: Steven Mackenzie (boost_at_[hidden])
Date: 2007-07-15 17:26:54


I think that your original interpretation of the wording was correct, and is the
intent of the library, and on Windows, clock does indeed measure elapsed time
http://msdn2.microsoft.com/en-us/library/4e2ess30(VS.71).aspx

Stroustrup suggests that clock can be used to be used to measure elapsed time in
The C++ Programming Language. But like you, I found that is not how it works for
Posix, and the different behaviours make clock (and libraries that use it)
unhelpful for anything intended to be cross platform.

Did you have any success using date_time to measure short durations precisly?
Could you post a short example?

Regards,
Steven

Ruediger Berlich wrote:
> Hi again,
>
> apologies - probably my last posting was a stupid one. I had
> interpreted "The timer library supplies a timer class for measuring elapsed
> time" in such a way that the library can be used to measure a given amount
> of real time. However, the library internally uses the clock() call,
> which "returns an approximation of processor time used by the program". As
> I have just used usleep calls to simulate activity, the timer always
> returned 0. I will use the date_time library now instead, as my application
> spends a lot of time being idle.
>
> Thanks and Best Regards,
> Ruediger
>
>
> Ruediger Berlich wrote:
>
>> Hi there,
>> the following program
>>
>> /****************************************************/
>>
>> #include <iostream>
>> #include <boost/timer.hpp>
>>
>> using namespace std;
>>
>> boost::timer t;
>>
>> main()
>> {
>> t.restart();
>> for(int i=0; i<5; i++){
>> usleep(500000);
>> cout << t.elapsed() << endl
>> << t.elapsed_min() << endl
>> << t.elapsed_max() << endl;
>> }
>> }
>>
>> /****************************************************/
>>
>> gives five times the following output, in 0.5 s intervals:
>>
>> 0
>> 1e-06
>> 9.22337e+12
>>
>> I have tried the timer_test.cpp application (from
>> http://www.boost.org/libs/timer/index.html). Most of it seems to be
>> working, but the first messages also say:
>>
>> timer::elapased_min() reports 1e-06 seconds
>> timer::elapased_max() reports 9.22337e+12 seconds,
>> which is 2.56205e+09 hours
>>
>> After this the output seems to be fine.
>>
>>
>> So something clearly is wrong. Any ideas ?
>>
>> This is on an OpenSuSE 10.2 system with a Boost 1.34.0 (with added ASIO
>> support, 0.38rc3). g++ is 4.1.2 .
>>
>> Thanks and Best Regards,
>> Ruediger


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