IBR-DTNSuite  0.8
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 #include <stdint.h>
00026 
00027 namespace ibrcommon
00028 {
00029         class TimeMeasurement
00030         {
00031         public:
00032                 TimeMeasurement();
00033                 virtual ~TimeMeasurement();
00034 
00035                 void start();
00036                 void stop();
00037 
00038                 u_int64_t getNanoseconds() const;
00039                 float getMicroseconds() const;
00040                 float getMilliseconds() const;
00041                 float getSeconds() const;
00042 
00043                 friend std::ostream &operator<<(std::ostream &stream, const TimeMeasurement &measurement);
00044 
00045                 static std::ostream& format(std::ostream &stream, const float value);
00046 
00047         private:
00048                 static int64_t timespecDiff(const struct timespec *timeA_p, const struct timespec *timeB_p);
00049                 static int64_t timespecDiff(const uint64_t &stop, const uint64_t &start);
00050 
00051                 struct timespec _start;
00052                 struct timespec _end;
00053 
00054                 uint64_t _uint64_start;
00055                 uint64_t _uint64_end;
00056         };
00057 }
00058 
00059 #endif /* TIMEMEASUREMENT_H_ */