diff --git a/gtsam/base/timing.cpp b/gtsam/base/timing.cpp index edb436822..ba784ffab 100644 --- a/gtsam/base/timing.cpp +++ b/gtsam/base/timing.cpp @@ -30,7 +30,9 @@ boost::shared_ptr timingRoot(new TimingOutline("Total")); boost::weak_ptr timingCurrent(timingRoot); -//Timing timing; +#ifdef ENABLE_OLD_TIMING +Timing timing; +#endif std::string timingPrefix; /* ************************************************************************* */ @@ -150,15 +152,27 @@ const boost::shared_ptr& TimingOutline::child(size_t child, const /* ************************************************************************* */ void TimingOutline::tic() { +#ifdef GTSAM_USING_NEW_BOOST_TIMERS assert(timer_.is_stopped()); timer_.start(); +#else + assert(!timerActive_); + timer_.restart(); + *timerActive_ = true; +#endif } /* ************************************************************************* */ void TimingOutline::toc() { +#ifdef GTSAM_USING_NEW_BOOST_TIMERS assert(!timer_.is_stopped()); timer_.stop(); add((timer_.elapsed().user + timer_.elapsed().system) / 1000); +#else + assert(timerActive_); + double elapsed = timer_.elapsed(); + add(size_t(elapsed * 1000000.0)); +#endif } /* ************************************************************************* */ diff --git a/gtsam/base/timing.h b/gtsam/base/timing.h index e09e3bb14..09d0a0da0 100644 --- a/gtsam/base/timing.h +++ b/gtsam/base/timing.h @@ -22,7 +22,17 @@ #include #include #include +#include + +#if BOOST_VERSION >= 104800 +#define GTSAM_USING_NEW_BOOST_TIMERS +#endif + +#ifdef GTSAM_USING_NEW_BOOST_TIMERS #include +#else +#include +#endif class TimingOutline; extern boost::shared_ptr timingRoot; @@ -40,7 +50,12 @@ protected: boost::weak_ptr parent_; std::vector > children_; +#ifdef GTSAM_USING_NEW_BOOST_TIMERS boost::timer::cpu_timer timer_; +#else + boost::timer timer_; + gtsam::ValueWithDefault timerActive_; +#endif void add(size_t usecs);