mptensor  v0.3.0
Parallel Library for Tensor Network Methods
timer.hpp
Go to the documentation of this file.
1 /*
2  mptensor - Parallel Library for Tensor Network Methods
3 
4  Copyright 2016 Satoshi Morita
5 
6  mptensor is free software: you can redistribute it and/or modify it
7  under the terms of the GNU Lesser General Public License as
8  published by the Free Software Foundation, either version 3 of the
9  License, or (at your option) any later version.
10 
11  mptensor is distributed in the hope that it will be useful, but
12  WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  Lesser General Public License for more details.
15 
16  You should have received a copy of the GNU Lesser General Public
17  License along with mptensor. If not, see
18  <https://www.gnu.org/licenses/>.
19 */
20 
28 #ifndef _TIMER_HPP_
29 #define _TIMER_HPP_
30 
31 #if __cplusplus >= 201103L
32 #include <chrono>
33 using namespace std::chrono;
34 
35 class Timer {
36  public:
37  Timer(){};
38  void now() { t = system_clock::now(); };
39 
40  private:
41  system_clock::time_point t;
42 
43  friend double operator-(Timer& t1, Timer& t0);
44 };
45 
46 inline double operator-(Timer& t1, Timer& t0) {
47  return double(duration_cast<microseconds>(t1.t - t0.t).count()) * 1.0e-6;
48 }
49 
50 #else
51 #include <ctime>
52 
53 class Timer {
54  public:
55  Timer(){};
56  void now() { t = std::clock(); };
57 
58  private:
59  clock_t t;
60 
61  friend double operator-(Timer& t1, Timer& t0);
62 };
63 
64 inline double operator-(Timer& t1, Timer& t0) {
65  return double(t1.t - t0.t) / CLOCKS_PER_SEC;
66 }
67 
68 #endif
69 
70 #endif // _MPI_TOOL_HPP_
Definition: timer.hpp:53
void now()
Definition: timer.hpp:56
Timer()
Definition: timer.hpp:55
double operator-(Timer &t1, Timer &t0)
Definition: timer.hpp:64