From 2fabfad4438d346cf6b77f25a05b71a5326a577a Mon Sep 17 00:00:00 2001 From: Gawain Bolton <45885849+gawain-bolton@users.noreply.github.com> Date: Thu, 10 Oct 2019 22:07:48 +0200 Subject: [PATCH] Improve performance of adding and subtracting time durations from a ptime. (#99) Modifying ptime objects by adding and subtracting time durations was inefficient because it extracted the date and time of day and then re-constructed a ptime using the date and modified time of day. This can be avoided by using the existing time_system utilities which perform the operation by adjusting the number of ticks. Performance is improved by a factor of 48 on my system. --- include/boost/date_time/time.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/boost/date_time/time.hpp b/include/boost/date_time/time.hpp index 632f10d7f..1eafe8810 100644 --- a/include/boost/date_time/time.hpp +++ b/include/boost/date_time/time.hpp @@ -164,7 +164,7 @@ namespace date_time { } time_type operator+=(const time_duration_type& td) { - time_ = (time_system::get_time_rep(date(), time_of_day() + td)); + time_ = time_system::add_time_duration(time_,td); return time_type(time_); } //! subtract time durations @@ -174,7 +174,7 @@ namespace date_time { } time_type operator-=(const time_duration_type& td) { - time_ = (time_system::get_time_rep(date(), time_of_day() - td)); + time_ = time_system::subtract_time_duration(time_, td); return time_type(time_); }