|
Boost : |
Subject: [boost] [date_time] local_date_time noticeably faster than ptime
From: oneill1979 (oneill1979_at_[hidden])
Date: 2009-01-30 07:21:00
We noticed recently that using a local_date_time in tight loops was several
times faster than using a ptime object. As these are both based largerly on
the same template code this was a surprise. It appears this is caused by the
implementation of the operater+=/-= and was wondering if there was any
justification for the difference or if this was just an oversight.
.\boost\date_time\local_time\local_date_time.hpp
//! Local_date_time += time_duration
local_date_time_base operator+=(const time_duration_type& td)
{
this->time_ = time_system_type::add_time_duration(this->time_,td);
return *this;
}
.\boost\date_time\time.hpp
time_type operator+=(const time_duration_type& td)
{
time_ = (time_system::get_time_rep(date(), time_of_day() + td));
return time_type(time_);
}
It looks like the ptime implementation is doing extra work to split the
ptime into date and time_duration components and if it is changed to follow
a similar pattern to that used in the local time the performance is then
indistinguishable.
time_type operator+=(const time_duration_type& td)
{
this->time_ = time_system::add_time_duration(this->time_, td);
return time_type(time_);
}
I can only think that maybe this was done to work around an issue and in
which case should the same then be applied to the local time implementation?
Paul.
-- View this message in context: http://www.nabble.com/-boost--date_time--local_date_time-noticeably-faster-than-ptime-tp21746180p21746180.html Sent from the Boost - Dev mailing list archive at Nabble.com.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk