Cadabra
Computer algebra system for field theory problems
Loading...
Searching...
No Matches
Stopwatch.hh
Go to the documentation of this file.
1/*
2
3Cadabra: a field-theory motivated computer algebra system.
4Copyright (C) 2001-2011 Kasper Peeters <kasper.peeters@aei.mpg.de>
5
6This program is free software: you can redistribute it and/or
7modify it under the terms of the GNU General Public License as
8 published by the Free Software Foundation, either version 3 of the
9License, or (at your option) any later version.
10
11This program is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14General Public License for more details.
15
16You 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
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_;
134
135 static const long s_to_us = 1000000L;
136 };
137
139std::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
friend 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 '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
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