rambrain
tester.h
Go to the documentation of this file.
1 /* rambrain - a dynamical physical memory extender
2  * Copyright (C) 2015 M. Imgrund, A. Arth
3  * mimgrund (at) mpifr-bonn.mpg.de
4  * arth (at) usm.uni-muenchen.de
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (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
14  * GNU 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 #ifndef TESTER_H
21 #define TESTER_H
22 
23 #include <vector>
24 #include <chrono>
25 #include <fstream>
26 #include <iostream>
27 #include <sstream>
28 
32 class tester
33 {
34 
35 public:
40  tester ( const char *name = "" );
44  ~tester();
45 
50  void addParameter ( char *param );
54  void addTimeMeasurement();
58  void addExternalTime ( std::chrono::duration<double> );
62  void addComment ( const char *comment );
67  void setSeed ( unsigned int seed = time ( NULL ) );
68 
74  int random ( int max ) const;
80  uint64_t random ( uint64_t max ) const;
86  double random ( double max = 1.0 ) const;
87 
93  void startNewTimeCycle();
99  void startNewRNGCycle();
100 
106  void writeToFile();
107 
112  std::vector<int64_t> getDurationsForCurrentCycle() const;
113 
114 private:
115  const char *name;
116  std::vector<char *> parameters;
117  std::vector<std::vector<std::chrono::high_resolution_clock::time_point> > timeMeasures;
118  std::string comment;
119  std::vector<unsigned int> seeds;
120  std::vector<bool> seeded;
121 
122 };
123 
124 #ifdef CAN_IGNORE_WARNINGS
125 #define STRINGIFY(a) #a
126 #define IGNORE_WARNING(warning) _Pragma(STRINGIFY(GCC diagnostic ignored #warning))
127 #define IGNORE_TEST_WARNINGS IGNORE_WARNING(-Wunknown-pragmas); \
128  IGNORE_WARNING(-Wunused-variable); \
129  IGNORE_WARNING(-Wdeprecated-declarations); \
130  IGNORE_WARNING(-Wsign-compare); \
131  IGNORE_WARNING(-Wunused-but-set-variable)
132 #define RESTORE_WARNING _Pragma("GCC diagnostic pop")
133 #define RESTORE_WARNINGS RESTORE_WARNING; RESTORE_WARNING; RESTORE_WARNING; RESTORE_WARNING; RESTORE_WARNING;
134 #else
135 #define IGNORE_WARNING(warning)
136 #define IGNORE_TEST_WARNINGS
137 #define RESTORE_WARNING
138 #define RESTORE_WARNINGS
139 #endif
140 
141 #endif // TESTER_H
142 
std::string comment
Definition: tester.h:118
void addTimeMeasurement()
Saves the current timestamp.
Definition: tester.cpp:36
void addComment(const char *comment)
Simple setter.
Definition: tester.cpp:59
void addExternalTime(std::chrono::duration< double >)
Add a duration to the timing list.
Definition: tester.cpp:45
tester(const char *name="")
tester Create a new tester
Definition: tester.cpp:22
void startNewRNGCycle()
Starts a new cycle of random numbers.
Definition: tester.cpp:94
const char * name
Definition: tester.h:115
void setSeed(unsigned int seed=time(NULL))
Set a new seed for random number generation.
Definition: tester.cpp:64
int random(int max) const
Get a random number (integer)
Definition: tester.cpp:74
void startNewTimeCycle()
Starts a new cycle of time measurements.
Definition: tester.cpp:89
std::vector< int64_t > getDurationsForCurrentCycle() const
Take the current cycle of time measurements and calculate all durations in betwen.
Definition: tester.cpp:186
std::vector< unsigned int > seeds
Definition: tester.h:119
A basic class to be used by tests. Provides helper methods and functionality e.g. time measurements...
Definition: tester.h:32
std::vector< std::vector< std::chrono::high_resolution_clock::time_point > > timeMeasures
Definition: tester.h:117
void writeToFile()
Write all collected information to file.
Definition: tester.cpp:100
~tester()
Cleans up and destroys the tester.
Definition: tester.cpp:27
std::vector< bool > seeded
Definition: tester.h:120
void addParameter(char *param)
Add a new parameter to the list of parameters.
Definition: tester.cpp:31
std::vector< char * > parameters
Definition: tester.h:116