Cadabra
Computer algebra system for field theory problems
Stopwatch.hh
Go to the documentation of this file.
1 /*
2 
3 Cadabra: a field-theory motivated computer algebra system.
4 Copyright (C) 2001-2011 Kasper Peeters <kasper.peeters@aei.mpg.de>
5 
6 This program is free software: you can redistribute it and/or
7 modify it under the terms of the GNU 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 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
15 
16 You should have received a copy of the GNU General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18 
19 */
20 
21 #ifndef stopwatch_hh__
22 #define stopwatch_hh__
23 
24 #include <chrono>
25 #include <iosfwd>
26 #include <iostream>
27 
106 
107 class Stopwatch {
108  public:
109  Stopwatch();
110 
111  typedef std::chrono::steady_clock clock;
112 
114  void reset();
116  void start();
118  void stop();
120  long seconds() const;
122  long useconds() const;
124  bool stopped() const;
125 
126  friend std::ostream& operator<<(std::ostream&, const Stopwatch&);
127 
128  private:
129  void checkpoint_() const;
130 
131  mutable clock::time_point start_;
132  mutable long elapsed_;
133  bool stopped_;
134 
135  static const long s_to_us = 1000000L;
136  };
137 
139 std::ostream& operator<<(std::ostream&, const Stopwatch&);
140 
141 #endif
std::ostream & operator<<(std::ostream &, const Stopwatch &)
Print human-readable representation of the time elapsed.
Definition: Stopwatch.cc:72
The Stopwach class provides a simple interace to allow timing function calls etc.....
Definition: Stopwatch.hh:107
long useconds() const
Number of micro-seconds elapsed (needs to be added to 'seconds').
Definition: Stopwatch.cc:66
long elapsed_
Definition: Stopwatch.hh:132
std::chrono::steady_clock clock
Definition: Stopwatch.hh:111
void reset()
Reset to no-time-elapsed.
Definition: Stopwatch.cc:29
bool stopped() const
Is the stopwatch currently timing?
Definition: Stopwatch.cc:47
friend std::ostream & operator<<(std::ostream &, const Stopwatch &)
Print human-readable representation of the time elapsed.
Definition: Stopwatch.cc:72
Stopwatch()
Definition: Stopwatch.cc:24
void checkpoint_() const
Definition: Stopwatch.cc:52
void start()
Continue timing (does not reset).
Definition: Stopwatch.cc:35
bool stopped_
Definition: Stopwatch.hh:133
clock::time_point start_
Definition: Stopwatch.hh:131
void stop()
Stop timing.
Definition: Stopwatch.cc:41
long seconds() const
Number of seconds elapsed.
Definition: Stopwatch.cc:60
static const long s_to_us
Definition: Stopwatch.hh:135