IBR-DTNSuite 0.6

ibrcommon/ibrcommon/TimeMeasurement.h

Go to the documentation of this file.
00001 /*
00002  * TimeMeasurement.h
00003  *
00004  * Copyright 2011 Johannes Morgenroth, IBR, TU Braunschweig
00005  *
00006  * Licensed under the Apache License, Version 2.0 (the "License");
00007  * you may not use this file except in compliance with the License.
00008  * You may obtain a copy of the License at
00009  *
00010  *     http://www.apache.org/licenses/LICENSE-2.0
00011  *
00012  * Unless required by applicable law or agreed to in writing, software
00013  * distributed under the License is distributed on an "AS IS" BASIS,
00014  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00015  * See the License for the specific language governing permissions and
00016  * limitations under the License.
00017  */
00018 
00019 #ifndef TIMEMEASUREMENT_H_
00020 #define TIMEMEASUREMENT_H_
00021 
00022 #include <time.h>
00023 #include <iostream>
00024 #include <sys/types.h>
00025 
00026 namespace ibrcommon
00027 {
00028         class TimeMeasurement
00029         {
00030         public:
00031                 TimeMeasurement();
00032                 virtual ~TimeMeasurement();
00033 
00034                 void start();
00035                 void stop();
00036 
00037                 float getNanoseconds();
00038                 float getMicroseconds();
00039                 float getMilliseconds();
00040                 float getSeconds();
00041 
00042                 friend std::ostream &operator<<(std::ostream &stream, TimeMeasurement &measurement);
00043 
00044                 static std::ostream& format(std::ostream &stream, const float value);
00045 
00046         private:
00047                 static int64_t timespecDiff(struct timespec *timeA_p, struct timespec *timeB_p);
00048 
00049                 struct timespec _start;
00050                 struct timespec _end;
00051         };
00052 }
00053 
00054 #endif /* TIMEMEASUREMENT_H_ */