IBR-DTNSuite  0.10
TimeMeasurement.h
Go to the documentation of this file.
1 /*
2  * TimeMeasurement.h
3  *
4  * Copyright (C) 2011 IBR, TU Braunschweig
5  *
6  * Written-by: Johannes Morgenroth <morgenroth@ibr.cs.tu-bs.de>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  */
21 
22 #ifndef TIMEMEASUREMENT_H_
23 #define TIMEMEASUREMENT_H_
24 
25 #include <time.h>
26 #include <iostream>
27 #include <sys/types.h>
28 #include <stdint.h>
29 
30 namespace ibrcommon
31 {
33  {
34  public:
36  virtual ~TimeMeasurement();
37 
38  void start();
39  void stop();
40 
41  double getMicroseconds() const;
42  double getMilliseconds() const;
43 
44  void getTime(struct timespec &diff) const;
45  time_t getSeconds() const;
46 
47  friend std::ostream &operator<<(std::ostream &stream, const TimeMeasurement &measurement);
48 
49  static std::ostream& format(std::ostream &stream, const double value);
50 
51  private:
52  void gettime(struct timespec *ts);
53 
54  struct timespec _start;
55  struct timespec _end;
56  };
57 }
58 
59 #endif /* TIMEMEASUREMENT_H_ */