41 std::chrono::high_resolution_clock::time_point t = std::chrono::high_resolution_clock::now();
48 std::chrono::high_resolution_clock::time_point t = std::chrono::high_resolution_clock::now();
52 std::chrono::high_resolution_clock::time_point t =
timeMeasures.back().back();
53 t += std::chrono::duration_cast< std::chrono::milliseconds > ( mdur );
61 this->comment = std::string ( comment );
71 std::cout <<
"I am running with a seed of " << seed << std::endl;
76 return static_cast<uint64_t
> ( rand() ) * max / RAND_MAX;
81 return random ( static_cast<double> ( max ) );
86 return drand48() * max;
91 timeMeasures.push_back ( std::vector<std::chrono::high_resolution_clock::time_point>() );
96 seeds.push_back ( 0u );
97 seeded.push_back (
false );
102 if ( std::string (
name ).empty() ) {
103 std::cerr <<
"Can not write to file without file name" << std::endl;
107 std::stringstream fileName;
110 fileName <<
"#" << *it;
112 std::ofstream out ( fileName.str(), std::ofstream::out );
121 out <<
"# " << cyclesCount <<
" cycles run for average" << std::endl;
123 bool firstSeed =
true;
124 for (
size_t i = 0; i <
seeded.size(); ++i ) {
127 out <<
"# Random seeds: ";
130 out <<
seeds[i] <<
" ";
141 out <<
"# Columns: (Time [ms], Start [ms], End [ms], Percentage) per repetition run and afterwards for average (without Start, End)" << std::endl;
144 out <<
"# " <<
comment << std::endl;
148 int64_t durations[timesCount][cyclesCount], starts[timesCount][cyclesCount], ends[timesCount][cyclesCount];
149 double percentages[timesCount][cyclesCount];
153 int64_t totms = std::chrono::duration_cast<std::chrono::milliseconds> ( repIt->back() - repIt->front() ).count();
156 for (
auto it = repIt->begin(), jt = repIt->begin() + 1; it != repIt->end() && jt != repIt->end(); ++it, ++jt, ++time ) {
157 starts[time][cycle] = std::chrono::duration_cast<std::chrono::milliseconds> ( it->time_since_epoch() ).count();
158 ends[time][cycle] = std::chrono::duration_cast<std::chrono::milliseconds> ( jt->time_since_epoch() ).count();
159 durations[time][cycle] = std::chrono::duration_cast<std::chrono::milliseconds> ( ( *jt ) - ( *it ) ).count();
160 percentages[time][cycle] = 100.0 * durations[time][cycle] / totms;
165 double avgPercentage;
166 for ( time = 0; time < timesCount; ++time ) {
171 for ( cycle = 0; cycle < cyclesCount; ++cycle ) {
172 avgTime += durations[time][cycle];
173 avgPercentage += percentages[time][cycle];
175 out << durations[time][cycle] <<
"\t" << starts[time][cycle] <<
"\t" << ends[time][cycle] <<
"\t" << percentages[time][cycle] <<
"\t";
177 avgTime /= cyclesCount;
178 avgPercentage /= cyclesCount;
180 out << avgTime <<
"\t" << avgPercentage << std::endl;
188 std::vector<int64_t> durations;
191 durations.push_back ( std::chrono::duration_cast<std::chrono::milliseconds> ( ( *jt ) - ( *it ) ).count() );
void addTimeMeasurement()
Saves the current timestamp.
void addComment(const char *comment)
Simple setter.
static void sigswapstats(int sig)
static binding that will print out some stats. Compile with cmake -DSWAPSTATS=on and send process SIG...
void addExternalTime(std::chrono::duration< double >)
Add a duration to the timing list.
tester(const char *name="")
tester Create a new tester
void startNewRNGCycle()
Starts a new cycle of random numbers.
void setSeed(unsigned int seed=time(NULL))
Set a new seed for random number generation.
int random(int max) const
Get a random number (integer)
void startNewTimeCycle()
Starts a new cycle of time measurements.
std::vector< int64_t > getDurationsForCurrentCycle() const
Take the current cycle of time measurements and calculate all durations in betwen.
std::vector< unsigned int > seeds
std::vector< std::vector< std::chrono::high_resolution_clock::time_point > > timeMeasures
void writeToFile()
Write all collected information to file.
~tester()
Cleans up and destroys the tester.
std::vector< bool > seeded
void addParameter(char *param)
Add a new parameter to the list of parameters.
std::vector< char * > parameters