- Main Page
- Classes
- Files

- File List

# OptFrame/Util/Timer.hpp

    00001 #ifndef TIMER_HPP
    00002 #define TIMER_HPP
    00003
    00004 #include <cstdio>
    00005 #include <cstdlib>
    00006 #include <ctime>
    00007 #include <sys/time.h>
    00008 #include <sys/timeb.h>
    00009 #include <sys/resource.h>
    00010
    00011 class Timer
    00012 {
    00013 protected:
    00014         double initialTime;
    00015
    00016         bool showMessageOnDestroy;
    00017
    00018         double get_clock_sec(void)
    00019         {  struct timeval t;
    00020                 struct timezone tz;
    00021                 gettimeofday(&t, &tz);
    00022                 return (double) t.tv_sec + (double) t.tv_usec * 1E-6;
    00023         };
    00024
    00025 public:
    00026         Timer(){ initialTime=get_clock_sec(); showMessageOnDestroy=true; };
    00027         Timer(bool m){ initialTime=get_clock_sec(); showMessageOnDestroy=m; };
    00028         virtual ~Timer(){ if(showMessageOnDestroy) printf("Spent time: %f secs\n", get_clock_sec() -initialTime) ; };
    00029         virtual double now() { return (get_clock_sec() - initialTime) ;  };
    00030
    00031 };
    00032
    00033 #endif /* TIMER_HPP */

All Classes Functions