TimeMeasure.h
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2008, AIST, the University of Tokyo and General Robotix Inc.
00003  * All rights reserved. This program is made available under the terms of the
00004  * Eclipse Public License v1.0 which accompanies this distribution, and is
00005  * available at http://www.eclipse.org/legal/epl-v10.html
00006  * Contributors:
00007  * The University of Tokyo
00008  * National Institute of Advanced Industrial Science and Technology (AIST)
00009  * General Robotix Inc. 
00010  */
00011 
00012 #ifndef OPENHRP_TIME_MEASURE_H_INCLUDED
00013 #define OPENHRP_TIME_MEASURE_H_INCLUDED
00014 
00015 
00016 #ifndef __WIN32__
00017 
00018 #include <sys/time.h>
00019 
00020 class TimeMeasure
00021 {
00022     struct timeval tv;
00023     double time_;
00024     double totalTime_;
00025     int numCalls;
00026     
00027  public:
00028     TimeMeasure() {
00029         totalTime_ = 0.0;
00030         numCalls = 0;
00031     }
00032 
00033     void begin() {
00034         gettimeofday(&tv, 0);
00035     }
00036 
00037     void end(){
00038         double beginTime = tv.tv_sec + (double)tv.tv_usec * 1.0e-6;
00039         gettimeofday(&tv, 0);
00040         double endTime = tv.tv_sec + (double)tv.tv_usec * 1.0e-6;
00041         time_ = endTime - beginTime;
00042         totalTime_ += time_;
00043         numCalls++;
00044     }
00045 
00046     double time() { return time_; }
00047     double totalTime() { return totalTime_; }
00048     double avarageTime() { return totalTime_ / numCalls; }
00049 
00050 };
00051 
00052 
00053 #else
00054 
00055 class TimeMeasure
00056 {
00057  public:
00058     TimeMeasure() { }
00059     void begin() { }
00060     void end(){ }
00061         double time() { return 0.0; }
00062     double totalTime() { return 0.0; }
00063     double avarageTime() { return 0.0; }
00064 };
00065 
00066 #endif
00067 
00068 
00069 #endif


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Sun Apr 2 2017 03:43:57