Boost logo

Boost Users :

From: Brian Neal (bgneal_at_[hidden])
Date: 2006-06-20 13:25:03


I wrote:
> I was thinking about adding a
> function to our code that called clock_gettime() (which is what our
> old code did), but then constructing a time_type out of that using the
> UNIX epoch for the date part and the results of clock_gettime() for
> the time_duration part, i.e, in pseudo code:
>
> time_type our_get_time() {
> clock_gettime(CLOCK_REALTIME, &timespec);
> time_duration td = massage(timespec);
> return time_type(unix_epoch, td);
> }

I ended up doing something like this:

struct timespec ts;
clock_gettime(CLOCK_REALTIME, &ts);
time_duration td(seconds(ts.tv_sec) + nanoseconds(ts.tv_nsec));
return ptime(epochDate, td);

where:

const date epochDate(1970, Jan, 1);

Wow...this turns out to be much, much slower, like 1000x slower, than
calling gettimeofday() followed by gmtime()......!

I guess it must be all the calculations involved to normalize the very
large seconds value offset from 1970 into a ptime.

Hmmm...back to the drawing board.


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