Cadabra
Computer algebra system for field theory problems
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 extern "C" {
25 #include <sys/time.h>
26 #include <unistd.h>
27 #include <signal.h>
28 }
29 
30 #include <iostream>
31 
32 class Stopwatch {
33  public:
34  Stopwatch();
35 
36  void reset();
37  void start();
38  void stop();
39  long seconds() const;
40  long useconds() const;
41  bool stopped() const;
42 
43  friend std::ostream& operator<<(std::ostream&, const Stopwatch&);
44 
45  private:
46  void checkpoint_() const;
47  mutable struct timeval tv1,tv2;
48  mutable struct timezone tz;
49  mutable long diffsec, diffusec;
50  bool stopped_;
51 };
52 
53 std::ostream& operator<<(std::ostream&, const Stopwatch&);
54 
55 #endif
struct timeval tv1 tv2
Definition: Stopwatch.hh:47
long seconds() const
Definition: Stopwatch.cc:70
struct timezone tz
Definition: Stopwatch.hh:48
std::ostream & operator<<(std::ostream &, const Stopwatch &)
Definition: Stopwatch.cc:82
Definition: Stopwatch.hh:32
void stop()
Definition: Stopwatch.cc:43
long diffsec
Definition: Stopwatch.hh:49
void checkpoint_() const
Definition: Stopwatch.cc:54
long useconds() const
Definition: Stopwatch.cc:76
bool stopped_
Definition: Stopwatch.hh:50
Stopwatch()
Definition: Stopwatch.cc:24
bool stopped() const
Definition: Stopwatch.cc:49
friend std::ostream & operator<<(std::ostream &, const Stopwatch &)
Definition: Stopwatch.cc:82
void start()
Definition: Stopwatch.cc:37
long diffusec
Definition: Stopwatch.hh:49
void reset()
Definition: Stopwatch.cc:30