15 #ifndef STXXL_TIMER_HEADER
16 #define STXXL_TIMER_HEADER
18 #ifdef STXXL_BOOST_TIMESTAMP
19 #include <boost/date_time/posix_time/posix_time.hpp>
26 #include <stxxl/bits/namespace.h>
29 __STXXL_BEGIN_NAMESPACE
35 #ifdef STXXL_BOOST_TIMESTAMP
36 boost::posix_time::ptime MyTime = boost::posix_time::microsec_clock::local_time();
37 boost::posix_time::time_duration Duration =
38 MyTime - boost::posix_time::time_from_string(
"1970-01-01 00:00:00.000");
39 double sec = double(Duration.hours()) * 3600. +
40 double(Duration.minutes()) * 60. +
41 double(Duration.seconds()) +
42 double(Duration.fractional_seconds()) / (pow(10., Duration.num_fractional_digits()));
46 gettimeofday(&tp, NULL);
47 return double(tp.tv_sec) + tp.tv_usec / 1000000.;
56 inline double timestamp();
59 inline timer(
bool start_immediately =
false);
63 inline double seconds();
64 inline double mseconds();
65 inline double useconds();
68 timer::timer(
bool start_immediately) : running(false), accumulated(0.)
70 if (start_immediately)
74 double timer::timestamp()
76 return stxxl::timestamp();
82 last_clock = timestamp();
88 accumulated += timestamp() - last_clock;
94 last_clock = timestamp();
97 double timer::mseconds()
100 return (accumulated + timestamp() - last_clock) * 1000.;
102 return (accumulated * 1000.);
105 double timer::useconds()
108 return (accumulated + timestamp() - last_clock) * 1000000.;
110 return (accumulated * 1000000.);
113 double timer::seconds()
116 return (accumulated + timestamp() - last_clock);
118 return (accumulated);
121 __STXXL_END_NAMESPACE
123 #endif // !STXXL_TIMER_HEADER