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 
103 
104 
105 class Stopwatch {
106  public:
107  Stopwatch();
108 
109  typedef std::chrono::steady_clock clock;
110 
112  void reset();
114  void start();
116  void stop();
118  long seconds() const;
120  long useconds() const;
122  bool stopped() const;
123 
124  friend std::ostream& operator<<(std::ostream&, const Stopwatch&);
125 
126  private:
127  void checkpoint_() const;
128 
129  mutable clock::time_point start_;
130  mutable long elapsed_;
131  bool stopped_;
132 
133  static const long s_to_us = 1000000L;
134 };
135 
137 std::ostream& operator<<(std::ostream&, const Stopwatch&);
138 
139 #endif
long seconds() const
Number of seconds elapsed.
Definition: Stopwatch.cc:60
long elapsed_
Definition: Stopwatch.hh:130
std::ostream & operator<<(std::ostream &, const Stopwatch &)
Print human-readable representation of the time elapsed.
Definition: Stopwatch.cc:72
long useconds() const
Number of micro-seconds elapsed (needs to be added to &#39;seconds&#39;).
Definition: Stopwatch.cc:66
The Stopwach class provides a simple interace to allow timing function calls etc...
Definition: Stopwatch.hh:105
void stop()
Stop timing.
Definition: Stopwatch.cc:41
std::chrono::steady_clock clock
Definition: Stopwatch.hh:109
clock::time_point start_
Definition: Stopwatch.hh:129
static const long s_to_us
Definition: Stopwatch.hh:133
bool stopped_
Definition: Stopwatch.hh:131
Stopwatch()
Definition: Stopwatch.cc:24
friend std::ostream & operator<<(std::ostream &, const Stopwatch &)
Print human-readable representation of the time elapsed.
Definition: Stopwatch.cc:72
void start()
Continue timing (does not reset).
Definition: Stopwatch.cc:35
void checkpoint_() const
Definition: Stopwatch.cc:52
bool stopped() const
Is the stopwatch currently timing?
Definition: Stopwatch.cc:47
void reset()
Reset to no-time-elapsed.
Definition: Stopwatch.cc:29