|
Boost : |
Subject: Re: [boost] [Chrono] Proposed library now feature complete
From: Howard Hinnant (hinnant_at_[hidden])
Date: 2008-11-18 19:56:10
On Nov 18, 2008, at 9:14 AM, Beman Dawes wrote:
> The Chrono library in the sandbox is now more-or-less feature
> complete. In addition to the C++0x features, timers have been added
> to replace the old Boost.Timer library which will become deprecated.
>
> The feature list includes:
>
> * The C++0x Standard Library's time utilities, including:
> o Class template duration
> o Class template time_point
> o Clocks:
> + |system_clock|
> + |monotonic_clock|
> + |high_resolution_clock|
> * Class template |timer|, with typedefs:
> o |system_timer|
> o |monotonic_timer|
> o |high_resolution_timer|
> * Process clocks and timers:
> o |process_clock|, capturing real, user-CPU, and system-CPU
> times.
> o |process_timer|, capturing elapsed real, user-CPU, and
> system-CPU times.
> o |run_timer|, convenient reporting of |process_timer|
> results.
> * The C++0x Standard Library's compile-time rational
> arithmetic.
>
> See http://svn.boost.org/svn/boost/sandbox/chrono
>
> The implementation is now working and lightly tested on Windows with
> VC++ 9.0 SP1 and Intel ia32 11.0 compilers, and on Ubuntu Linux with
> GCC 4.2.4 compiler.
>
> There is a bit more documentation, but it is still needs much work.
>
> Comments are welcome.
It seems a shame that process_clock does not really meet the proposed
standard clock requirements (its now() doesn't return the
time_point). That being said, I can see why you didn't. This clock
really has 3 distinct "time points" and one needs to set each of those
three with one system call. If one wanted, one could easily create a
user_time_clock wrapper around processor_clock to adapt it to the
standard clock requirements if needed.
Just for general education purposes, here's a portable processor-time
clock (just to show how easy it is to build a custom clock):
#include <ctime>
#include <cstdio>
#include <chrono>
class processor_clock
{
public:
typedef std::clock_t rep;
typedef std::ratio<1, CLOCKS_PER_SEC> period;
typedef std::chrono::duration<rep, period> duration;
typedef std::chrono::time_point<processor_clock> time_point;
static const bool is_monotonic = true;
static time_point now() {return
time_point(duration(std::clock()));}
};
int main()
{
processor_clock::time_point t1 = processor_clock::now();
processor_clock::time_point t2 = processor_clock::now();
std::printf("%g seconds\n", std::chrono::duration<double>(t2-
t1).count());
}
Output:
4e-06 seconds
-Howard
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk