Using boost timer instead of chrono to support older boost versions

release/4.3a0
Richard Roberts 2012-06-05 20:03:31 +00:00
parent 1b5b4d494e
commit dacff98f9f
3 changed files with 214 additions and 218 deletions

View File

@ -20,7 +20,6 @@
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <sys/time.h>
#include <stdlib.h>
#include <boost/foreach.hpp>
#include <boost/format.hpp>
@ -48,7 +47,7 @@ void TimingOutline::add(size_t usecs) {
/* ************************************************************************* */
TimingOutline::TimingOutline(const std::string& label) :
t_(0), t2_(0.0), tIt_(0), tMax_(0), tMin_(0), n_(0), label_(label), timerActive_(false) {}
t_(0), t2_(0.0), tIt_(0), tMax_(0), tMin_(0), n_(0), label_(label) {}
/* ************************************************************************* */
size_t TimingOutline::time() const {
@ -151,18 +150,15 @@ const boost::shared_ptr<TimingOutline>& TimingOutline::child(size_t child, const
/* ************************************************************************* */
void TimingOutline::tic() {
assert(!timerActive_);
timerActive_ = true;
gettimeofday(&t0_, NULL);
assert(timer_.is_stopped());
timer_.start();
}
/* ************************************************************************* */
void TimingOutline::toc() {
struct timeval t;
gettimeofday(&t, NULL);
assert(timerActive_);
add(t.tv_sec*1000000 + t.tv_usec - (t0_.tv_sec*1000000 + t0_.tv_usec));
timerActive_ = false;
assert(!timer_.is_stopped());
timer_.stop();
add((timer_.elapsed().user + timer_.elapsed().system) / 1000);
}
/* ************************************************************************* */
@ -231,6 +227,8 @@ void toc_(size_t id, const std::string& label) {
toc_(id);
}
#ifdef ENABLE_OLD_TIMING
/* ************************************************************************* */
// Timing class implementation
void Timing::print() {
@ -260,3 +258,5 @@ void ticPop_(const std::string& prefix, const std::string& id) {
else
timingPrefix.resize(timingPrefix.size() - prefix.size() - 1);
}
#endif

View File

@ -22,6 +22,7 @@
#include <vector>
#include <boost/shared_ptr.hpp>
#include <boost/weak_ptr.hpp>
#include <boost/timer/timer.hpp>
class TimingOutline;
extern boost::shared_ptr<TimingOutline> timingRoot;
@ -39,8 +40,7 @@ protected:
boost::weak_ptr<TimingOutline> parent_;
std::vector<boost::shared_ptr<TimingOutline> > children_;
struct timeval t0_;
bool timerActive_;
boost::timer::cpu_timer timer_;
void add(size_t usecs);
@ -89,6 +89,18 @@ inline void toc(size_t, const char*) {}
inline void tictoc_finishedIteration() {}
#endif
inline void tictoc_print_() {
timingRoot->print();
}
/* print mean and standard deviation */
inline void tictoc_print2_() {
timingRoot->print2();
}
#ifdef ENABLE_OLD_TIMING
// simple class for accumulating execution timing information by name
class Timing;
extern Timing timing;
@ -100,7 +112,6 @@ double tic(const std::string& id);
double toc(const std::string& id);
void ticPush(const std::string& id);
void ticPop(const std::string& id);
void tictoc_print();
void tictoc_finishedIteration();
/** These underscore versions work evening when ENABLE_TIMING is not defined */
@ -110,7 +121,6 @@ double tic_(const std::string& id);
double toc_(const std::string& id);
void ticPush_(const std::string& id);
void ticPop_(const std::string& id);
void tictoc_print_();
void tictoc_finishedIteration_();
@ -173,16 +183,6 @@ inline void ticPush_(const std::string& prefix, const std::string& id) {
}
void ticPop_(const std::string& prefix, const std::string& id);
inline void tictoc_print_() {
timing.print();
timingRoot->print();
}
/* print mean and standard deviation */
inline void tictoc_print2_() {
timingRoot->print2();
}
#ifdef ENABLE_TIMING
inline double _tic() { return _tic_(); }
inline double _toc(double t) { return _toc_(t); }
@ -200,3 +200,5 @@ inline void ticPush(const std::string&, const std::string&) {}
inline void ticPop(const std::string&, const std::string&) {}
inline void tictoc_print() {}
#endif
#endif

View File

@ -140,19 +140,13 @@ SharedDiagonal Gaussian::Cholesky(Matrix& Ab, size_t nFrontals) const {
// TODO: really no rank problems ?
// pre-whiten everything (cheaply if possible)
tic("Cholesky: 1 whiten");
WhitenInPlace(Ab);
toc("Cholesky: 1 whiten");
// Form A'*A (todo: this is probably less efficient than possible)
tic("Cholesky: 2 A' * A");
Ab = Ab.transpose() * Ab;
toc("Cholesky: 2 A' * A");
// Use Cholesky to factor Ab
tic("Cholesky: 3 careful");
size_t maxrank = choleskyCareful(Ab).first;
toc("Cholesky: 3 careful");
// Due to numerical error the rank could appear to be more than the number
// of variables. The important part is that it does not includes the