n2p2 - A neural network potential package
Stopwatch.h
Go to the documentation of this file.
1// n2p2 - A neural network potential package
2// Copyright (C) 2018 Andreas Singraber (University of Vienna)
3//
4// This program is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// This program is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with this program. If not, see <https://www.gnu.org/licenses/>.
16
17#ifndef STOPWATCH_H
18#define STOPWATCH_H
19
20#if !(defined(__linux__) || defined(__MACH__))
21#pragma message("WARNING: Platform not supported.")
22#define N2P2_NO_TIME
23#endif
24
25#ifdef N2P2_NO_TIME
26#pragma message("WARNING: Compiling dummy Stopwatch class (-DN2P2_NO_TIME).")
27#endif
28
29#include <ctime>
30#ifdef __MACH__
31#include <mach/mach_time.h>
32#endif
33
34namespace nnp
35{
36
39{
40
41public:
42 Stopwatch();
50 void start(bool newLoop = true);
52 double stop();
54 double loop();
56 double getTotal() const {return timeTotal;};
58 double getLoop() const {return timeLoop;};
60 void reset();
61
62private:
63 enum State
64 {
67 };
68
71 static const double NSEC;
72 double timeTotal;
73 double timeLoop;
74#ifdef N2P2_NO_TIME
75#elif __linux__
76 timespec time;
77#elif __MACH__
78 uint64_t time;
79#endif
80
81 void stopTime();
82 double updateTime();
83};
84
85}
86
87#endif
Implements a simple stopwatch on different platforms.
Definition: Stopwatch.h:39
double getTotal() const
Return total time elapsed (of a stopped watch).
Definition: Stopwatch.h:56
double updateTime()
Definition: Stopwatch.cpp:102
double timeLoop
Definition: Stopwatch.h:73
void reset()
Reset stopwatch (total and loop time zero, clock not running).
Definition: Stopwatch.cpp:76
bool resetLoop
Definition: Stopwatch.h:70
void stopTime()
Definition: Stopwatch.cpp:92
double stop()
Stop and return total time.
Definition: Stopwatch.cpp:62
void start(bool newLoop=true)
Start the stopwatch.
Definition: Stopwatch.cpp:40
double getLoop() const
Return time elapsed in last loop interval (of a stopped watch).
Definition: Stopwatch.h:58
double timeTotal
Definition: Stopwatch.h:72
double loop()
Stop and return loop time.
Definition: Stopwatch.cpp:69
static const double NSEC
Definition: Stopwatch.h:71
Definition: Atom.h:29