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.;
77 inline timer(
bool start_immediately =
false)
78 : running(false), accumulated(0.), last_clock(0)
80 if (start_immediately) start();
108 return (accumulated +
timestamp() - last_clock) * 1000.;
110 return (accumulated * 1000.);
117 return (accumulated +
timestamp() - last_clock) * 1000000.;
119 return (accumulated * 1000000.);
126 return (accumulated +
timestamp() - last_clock);
128 return (accumulated);
151 : m_message(message),
164 <<
" after " << m_timer.seconds() <<
" seconds");
167 double bps = (double)m_bytes / m_timer.seconds();
171 <<
" after " << m_timer.seconds() <<
" seconds. "
182 #endif // !STXXL_COMMON_TIMER_HEADER
~scoped_print_timer()
on destruction: tell the time
double mseconds()
return currently accumulated time in milliseconds
std::string m_message
message
unsigned long long int uint64
Simple scoped timer, which takes a text message and prints the duration until the scope is destroyed...
void reset()
return accumulated time
#define STXXL_BEGIN_NAMESPACE
timer(bool start_immediately=false)
double seconds()
return currently accumulated time in seconds (as double)
double useconds()
return currently accumulated time in microseconds
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...
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
#define STXXL_END_NAMESPACE
uint64 m_bytes
bytes processed