16 #ifndef STXXL_COMMON_TIMER_HEADER
17 #define STXXL_COMMON_TIMER_HEADER
24 #if STXXL_BOOST_TIMESTAMP
25 #include <boost/date_time/posix_time/posix_time.hpp>
46 #if STXXL_BOOST_TIMESTAMP
47 boost::posix_time::ptime MyTime = boost::posix_time::microsec_clock::local_time();
48 boost::posix_time::time_duration Duration =
49 MyTime - boost::posix_time::time_from_string(
"1970-01-01 00:00:00.000");
50 double sec = double(Duration.hours()) * 3600. +
51 double(Duration.minutes()) * 60. +
52 double(Duration.seconds()) +
53 double(Duration.fractional_seconds()) / (pow(10., Duration.num_fractional_digits()));
56 return GetTickCount() / 1000.0;
59 gettimeofday(&tp, NULL);
60 return double(tp.tv_sec) + double(tp.tv_usec) / 1000000.;
89 static const bool is_real =
true;
92 inline timer(
bool start_immediately =
false)
93 : running(false), accumulated(0), last_clock(0)
95 if (start_immediately) start();
123 return (accumulated +
timestamp() - last_clock) * 1000.;
125 return (accumulated * 1000.);
132 return (accumulated +
timestamp() - last_clock) * 1000000.;
134 return (accumulated * 1000000.);
141 return (accumulated +
timestamp() - last_clock);
143 return (accumulated);
159 return os << t.
seconds() <<
's';
174 static const bool is_real =
false;
195 return std::numeric_limits<double>::quiet_NaN();
201 return std::numeric_limits<double>::quiet_NaN();
207 return std::numeric_limits<double>::quiet_NaN();
219 return os << t.
seconds() <<
's';
242 : m_message(message),
255 <<
" after " << m_timer.seconds() <<
" seconds");
258 double bps = (double)m_bytes / m_timer.seconds();
262 <<
" after " << m_timer.seconds() <<
" seconds. "
279 #endif // !STXXL_COMMON_TIMER_HEADER
~scoped_print_timer()
on destruction: tell the time
bool running
boolean whether the stopwatch timer is currently running
friend std::ostream & operator<<(std::ostream &os, const uint_pair &a)
make a uint_pair outputtable via iostreams, using unsigned long long.
double mseconds() const
return currently accumulated time in milliseconds
std::string m_message
message
fake_timer(bool=false)
initialize and optionally immediately start the timer
unsigned long long int uint64
Simple scoped timer, which takes a text message and prints the duration until the scope is destroyed...
double useconds() const
return currently accumulated time in microseconds
Class fake_timer is a drop-in replacement for timer, which does nothing.
stxxl::timer m_timer
timer
uint_pair & operator+=(const uint_pair &b)
addition operator (uses 64-bit arithmetic)
void reset()
return accumulated time
double seconds() const
return currently accumulated time in seconds (as double)
void reset()
return accumulated time
double seconds() const
return currently accumulated time in seconds (as double)
#define STXXL_BEGIN_NAMESPACE
timer(bool start_immediately=false)
initialize and optionally immediately start the timer
static double timestamp()
return current timestamp
std::string format_IEC_size(uint64 number)
Format a byte size using IEC (Ki, Mi, Gi, Ti) suffixes (powers of two). Returns "123 Ki" or similar...
const stxxl::timer & timer() const
constant access to enclosed timer
double accumulated
total accumulated time in seconds.
double last_clock
last start time of the stopwatch
double useconds() const
return currently accumulated time in microseconds
static const size_t bytes
number of bytes in uint_pair
double timestamp()
Returns number of seconds since the epoch, high resolution.
scoped_print_timer(const std::string &message, const uint64 bytes=0)
save message and start timer
Class timer is a simple stop watch timer.
#define STXXL_END_NAMESPACE
double mseconds() const
return currently accumulated time in milliseconds
uint64 m_bytes
bytes processed