|
Boost : |
Subject: Re: [boost] [Chrono] Proposed library now feature complete
From: Beman Dawes (bdawes_at_[hidden])
Date: 2008-11-18 20:28:17
On Tue, Nov 18, 2008 at 7:56 PM, Howard Hinnant <hinnant_at_[hidden]> wrote:
> 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.
Yep, and I couldn't see any practical downside to the proposed now()
signature. Other than that, I did try to make process_clock conform.
> 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.
Yes. Interesting. That hadn't occurred to me.
> 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
I'll add that to the docs. The clock requirements are really nice;
they are totally minimalist, yet provide all the functionality needed.
Did you look at the boost/chrono/timer.hpp header? It supplies a timer
template to create a timer from any clock. I'd be curious to get your
reactionsl
Thanks,
--Beman
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk