IBR-DTNSuite  0.12
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 
34 #ifdef __WIN32__
35 #include <windows.h>
36 #include <pthread.h>
37 #endif
38 
39 namespace ibrcommon
40 {
42  {
43  public:
45  virtual ~TimeMeasurement();
46 
47  void start();
48  void stop();
49 
50  double getMicroseconds() const;
51  double getMilliseconds() const;
52 
53  void getTime(struct timespec &diff) const;
54  time_t getSeconds() const;
55 
56  friend std::ostream &operator<<(std::ostream &stream, const TimeMeasurement &measurement);
57 
58  static std::ostream& format(std::ostream &stream, const double value);
59 
60  private:
61  struct timespec _start;
62  struct timespec _end;
63  };
64 }
65 
66 #endif /* TIMEMEASUREMENT_H_ */