|
Revision 2, 2.0 KB
(checked in by emasson, 3 years ago)
|
|
initial import for the community edition
|
| Line | |
|---|
| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | #ifndef _TIMER_H_ |
|---|
| 10 | #define _TIMER_H_ |
|---|
| 11 | |
|---|
| 12 | #define TIMER_H_CVSID "$Id: timer.h,v 1.1.1.1 2008/05/04 15:53:48 emasson Exp $" |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | |
|---|
| 22 | #include "timeval.h" |
|---|
| 23 | |
|---|
| 24 | class Timer { |
|---|
| 25 | public: |
|---|
| 26 | Timer( int start = 0 ) { if ( start ) Timer::start(); } |
|---|
| 27 | ~Timer( void ){} |
|---|
| 28 | |
|---|
| 29 | void start( void ) { gettimeofday( &starttime_, NULL ); } |
|---|
| 30 | void stop( void ) { gettimeofday( &stoptime_, NULL ); } |
|---|
| 31 | |
|---|
| 32 | |
|---|
| 33 | |
|---|
| 34 | |
|---|
| 35 | |
|---|
| 36 | |
|---|
| 37 | #if 0 |
|---|
| 38 | LONG_LONG report( void ) const { |
|---|
| 39 | err << "This function Timer::report() should no longer be used!\n"; |
|---|
| 40 | exit(-1); |
|---|
| 41 | return (stoptime_.tv_sec - starttime_.tv_sec) * 1000000 |
|---|
| 42 | + stoptime_.tv_usec - starttime_.tv_usec; |
|---|
| 43 | } |
|---|
| 44 | #endif |
|---|
| 45 | |
|---|
| 46 | |
|---|
| 47 | double report_usecs(void) const { |
|---|
| 48 | return (stoptime_.tv_sec - starttime_.tv_sec) * 1000000.0 |
|---|
| 49 | + stoptime_.tv_usec - starttime_.tv_usec; |
|---|
| 50 | } |
|---|
| 51 | |
|---|
| 52 | std::ostream &printOn(std::ostream &os) const { |
|---|
| 53 | return os <<"Timer : [" |
|---|
| 54 | <<"starttime_ = " <<TimeVal(starttime_) |
|---|
| 55 | <<", stoptime_ = " <<TimeVal(stoptime_) |
|---|
| 56 | <<", duration = " <<report_usecs() <<" usecs]"; |
|---|
| 57 | } |
|---|
| 58 | |
|---|
| 59 | protected: |
|---|
| 60 | struct timeval starttime_, stoptime_; |
|---|
| 61 | |
|---|
| 62 | private: |
|---|
| 63 | }; |
|---|
| 64 | |
|---|
| 65 | inline std::ostream &operator<<(std::ostream &os, const Timer &t){ |
|---|
| 66 | return t.printOn(os); |
|---|
| 67 | } |
|---|
| 68 | |
|---|
| 69 | #endif |
|---|