text: #include <boost/date_time/posix_time/posix_time.hpp>
  
  #include "caffe/common.hpp"
  #include "caffe/util/benchmark.hpp"
  
  namespace caffe {
  
  Timer::Timer()
      : initted_(false), running_(false), has_run_at_least_once_(false) {
    Init();
  }
  
  Timer::~Timer() {
  }
  
  void Timer::Start() {
    if (!running()) {
      start_cpu_ = boost::posix_time::microsec_clock::local_time();
      running_ = true;
      has_run_at_least_once_ = true;
    }
  }
  
  void Timer::Stop() {
    if (running()) {
      stop_cpu_ = boost::posix_time::microsec_clock::local_time();
      running_ = false;
    }
  }
  
  float Timer::MicroSeconds() {
    if (!has_run_at_least_once()) {
      LOG(WARNING) << "Timer has never been run before reading time.";
      return 0;
    }
    if (running()) {
      Stop();
    }
  
    elapsed_microseconds_ = (stop_cpu_ - start_cpu_).total_microseconds();
    return elapsed_microseconds_;
  }
  
  float Timer::MilliSeconds() {
    if (!has_run_at_least_once()) {
      LOG(WARNING) << "Timer has never been run before reading time.";
      return 0;
    }
    if (running()) {
      Stop();
    }
  
    elapsed_milliseconds_ = (stop_cpu_ - start_cpu_).total_milliseconds();
    return elapsed_milliseconds_;
  }
  
  float Timer::Seconds() {
    return MilliSeconds() / 1000.;
  }
  
  void Timer::Init() {
    if (!initted()) {
      if (Caffe::mode() == Caffe::GPU) {
      }
      initted_ = true;
    }
  }
  
  CPUTimer::CPUTimer() {
    this->initted_ = true;
    this->running_ = false;
    this->has_run_at_least_once_ = false;
  }
  
  void CPUTimer::Start() {
    if (!running()) {
      this->start_cpu_ = boost::posix_time::microsec_clock::local_time();
      this->running_ = true;
      this->has_run_at_least_once_ = true;
    }
  }
  
  void CPUTimer::Stop() {
    if (running()) {
      this->stop_cpu_ = boost::posix_time::microsec_clock::local_time();
      this->running_ = false;
    }
  }
  
  float CPUTimer::MilliSeconds() {
    if (!has_run_at_least_once()) {
      LOG(WARNING) << "Timer has never been run before reading time.";
      return 0;
    }
    if (running()) {
      Stop();
    }
    this->elapsed_milliseconds_ =
        (this->stop_cpu_ - this->start_cpu_).total_milliseconds();
    return this->elapsed_milliseconds_;
  }
  
  float CPUTimer::MicroSeconds() {
    if (!has_run_at_least_once()) {
      LOG(WARNING) << "Timer has never been run before reading time.";
      return 0;
    }
    if (running()) {
      Stop();
    }
    this->elapsed_microseconds_ =
        (this->stop_cpu_ - this->start_cpu_).total_microseconds();
    return this->elapsed_microseconds_;
  }
  
  }  // namespace caffe
  