Scid  4.7.0
timer.h
Go to the documentation of this file.
1 /*
2 * Copyright (C) 2014 Fulvio Benini
3 
4 * This file is part of Scid (Shane's Chess Information Database).
5 *
6 * Scid is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation.
9 *
10 * Scid is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with Scid. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 #ifndef SCID_TIMER_H
20 #define SCID_TIMER_H
21 
22 #include <chrono>
23 class Timer {
24  decltype(std::chrono::system_clock::now()) start_;
25 public:
26  Timer() { Reset(); }
27  void Reset() { start_ = std::chrono::system_clock::now(); }
28  long long MilliSecs (void) const {
29  auto t = std::chrono::system_clock::now();
30  return std::chrono::duration_cast<std::chrono::milliseconds>(t - start_).count();
31  }
32  long long CentiSecs () const { return MilliSecs() / 10; }
33 };
34 
35 template <class S>
36 auto operator<<(S& os, const Timer& timer) -> decltype(os) {
37  return os << timer.MilliSecs() << " milliseconds\n";
38 }
39 
40 /* Usage:
41 Timer t;
42 //do some stuff
43 std::cout << "Elapsed: " << t;
44 */
45 
46 
47 #endif //SCID_TIMER_H
long long MilliSecs(void) const
Definition: timer.h:28
Timer()
Definition: timer.h:26
Definition: timer.h:23
void Reset()
Definition: timer.h:27
long long CentiSecs() const
Definition: timer.h:32
auto operator<<(S &os, const Timer &timer) -> decltype(os)
Definition: timer.h:36