Skip to content

Commit

Permalink
Improve performance of adding and subtracting time durations from a p…
Browse files Browse the repository at this point in the history
…time. (splunk#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.
  • Loading branch information
gawain-bolton authored and JeffGarland committed Oct 10, 2019
1 parent 3cc68a4 commit 2fabfad
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions include/boost/date_time/time.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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_);
}

Expand Down

0 comments on commit 2fabfad

Please sign in to comment.