allow to keep track of time with a precision of a microseconds. More...
#include <util/timestamp.hpp>
allow to keep track of time with a precision of a microseconds.
The default constructors obtains the time with gettimeofday(2). Timestamps can be added or substracted and pushed to streams such as std::cout. It keeps track of time using integers so as not to lose precision. Typical use of the class are:
or
timestamp acc (0,0); while (some_condition()){ do_stuff(); timestamp t1; do_important_stuff(); timestamp t2; acc += t2-t1; do_more_stuff(); } std::cout<<"do_important_stuff() took "<<acc<<" seconds"<<std::endl;
Public Member Functions | |
| timestamp () | |
| obtains time using gettimeofday(2) | |
| timestamp (int s, int us) | |
| provides time in seconds and microseconds | |
| timestamp | operator+ (const timestamp &b) |
| timestamp | operator- (const timestamp &b) |
| const timestamp & | operator+= (const timestamp &b) |
| const timestamp & | operator-= (const timestamp &b) |
Private Member Functions | |
| void | fixme () |
| fix overflow after an add or a substract. | |
Private Attributes | |
| int | seconds |
| int | microseconds |
Friends | |
| std::ostream & | operator<< (std::ostream &, const util::timestamp &) |
| util::timestamp::timestamp | ( | ) | [inline] |
obtains time using gettimeofday(2)
| util::timestamp::timestamp | ( | int | s, | |
| int | us | |||
| ) | [inline] |
provides time in seconds and microseconds
| void util::timestamp::fixme | ( | ) | [inline, private] |
fix overflow after an add or a substract.
Notice it only fix the overflow of one unit.
| std::ostream& operator<< | ( | std::ostream & | out, | |
| const util::timestamp & | t | |||
| ) | [friend] |
int util::timestamp::microseconds [private] |
int util::timestamp::seconds [private] |
1.7.1