A monte carlo pin cell spectral code for nuclear engineering applications.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
Timer.h
Go to the documentation of this file.
1 
8 #ifndef TIMER_H_
9 #define TIMER_H_
10 
11 #ifdef __cplusplus
12 #include <time.h>
13 #include <sys/time.h>
14 #include <iostream>
15 #include <sstream>
16 #include <iomanip>
17 #include <utility>
18 #include <vector>
19 #include "log.h"
20 #endif
21 
22 #ifdef __MACH__ /* For OSX */
23 #define timespec timeval
24 #endif
25 
26 
34 class Timer {
35 protected:
37  timespec _start_time;
39  timespec _end_time;
41  double _elapsed_time;
43  bool _running;
45  std::vector< std::pair<double, const char*> > _timer_splits;
46 public:
47  Timer();
48  virtual ~Timer();
49  void start();
50  void stop();
51  void restart();
52  void reset();
53  void recordSplit(const char* msg);
54  double getTime();
55  double diff(timespec start, timespec end);
56  void printSplits();
57 };
58 
59 #endif /* TIMER_H_ */
void printSplits()
Prints the Timer's splits to the console.
Definition: Timer.cpp:176
double _elapsed_time
Definition: Timer.h:41
double diff(timespec start, timespec end)
Helper function which computes the time between the values of two timespec structs.
Definition: Timer.cpp:134
double getTime()
Returns the amount of time elapsed from start to stop of the timer.
Definition: Timer.cpp:99
void reset()
Resets the timer in a similar fashion to resetting a stopwatch.
Definition: Timer.cpp:60
virtual ~Timer()
Default Timer destructor.
Definition: Timer.cpp:18
timespec _end_time
Definition: Timer.h:39
timespec _start_time
Definition: Timer.h:37
Timer()
Timer class constructor.
Definition: Timer.cpp:9
void start()
Starts the Timer in a similar fashion to starting a stopwatch.
Definition: Timer.cpp:24
std::vector< std::pair< double, const char * > > _timer_splits
Definition: Timer.h:45
void recordSplit(const char *msg)
Records a message corresponding to a given time recorded by the timer.
Definition: Timer.cpp:87
void restart()
Restarts the timer.
Definition: Timer.cpp:72
The Timer represents a simulation stopwatch.
Definition: Timer.h:34
Utility functions for writing log messages to the screen.
void stop()
Stops the timer in a similar fashion to stopping a stopwatch.
Definition: Timer.cpp:42
bool _running
Definition: Timer.h:43