Commit 86249c57 by Joao Paulo Magalhaes

Result checking: move some function definitions to source file.

parent 03b0655d
...@@ -65,6 +65,11 @@ void RunOutputTests(int argc, char* argv[]); ...@@ -65,6 +65,11 @@ void RunOutputTests(int argc, char* argv[]);
struct ResultsCheckerEntry; struct ResultsCheckerEntry;
typedef std::function< void(ResultsCheckerEntry const&) > ResultsCheckFn; typedef std::function< void(ResultsCheckerEntry const&) > ResultsCheckFn;
// Add a function to check the (CSV) results of a benchmark. These
// functions will be called only after the output was successfully
// checked.
size_t AddChecker(const char* bm_name, ResultsCheckFn fn);
// Class to test the results of a benchmark. // Class to test the results of a benchmark.
// It inspects the results by looking at the CSV output of a subscribed // It inspects the results by looking at the CSV output of a subscribed
// benchmark. // benchmark.
...@@ -74,17 +79,7 @@ struct ResultsCheckerEntry { ...@@ -74,17 +79,7 @@ struct ResultsCheckerEntry {
ResultsCheckerEntry(std::string const& n) : name(n) {} ResultsCheckerEntry(std::string const& n) : name(n) {}
int NumThreads() const { int NumThreads() const;
auto pos = name.find("/threads:");
if(pos == name.npos) return 1;
auto end = name.find('/', pos + 9);
std::stringstream ss;
ss << name.substr(pos + 9, end);
int num = 1;
ss >> num;
CHECK(!ss.fail());
return num;
}
// get the real_time duration of the benchmark in seconds // get the real_time duration of the benchmark in seconds
double DurationRealTime() const { double DurationRealTime() const {
...@@ -125,30 +120,9 @@ struct ResultsCheckerEntry { ...@@ -125,30 +120,9 @@ struct ResultsCheckerEntry {
} }
// get cpu_time or real_time in seconds // get cpu_time or real_time in seconds
double GetTime(const char* which) const { double GetTime(const char* which) const;
double val = GetAs< double >(which);
auto unit = Get("time_unit");
CHECK(unit);
if(*unit == "ns") {
return val * 1.e-9;
} else if(*unit == "us") {
return val * 1.e-6;
} else if(*unit == "ms") {
return val * 1.e-3;
} else if(*unit == "s") {
return val;
} else {
CHECK(1 == 0) << "unknown time unit: " << *unit;
return 0;
}
}
}; };
// Add a function to check the (CSV) results of a benchmark. These
// functions will be called only after the output was successfully
// checked.
size_t AddChecker(const char* bm_name, ResultsCheckFn fn);
//---------------------------------- //----------------------------------
// Macros to help in result checking. Do not use them with arguments causing // Macros to help in result checking. Do not use them with arguments causing
// side-effects. // side-effects.
......
...@@ -293,6 +293,36 @@ size_t AddChecker(const char* bm_name, ResultsCheckFn fn) ...@@ -293,6 +293,36 @@ size_t AddChecker(const char* bm_name, ResultsCheckFn fn)
return rc.results.size(); return rc.results.size();
} }
int ResultsCheckerEntry::NumThreads() const {
auto pos = name.find("/threads:");
if(pos == name.npos) return 1;
auto end = name.find('/', pos + 9);
std::stringstream ss;
ss << name.substr(pos + 9, end);
int num = 1;
ss >> num;
CHECK(!ss.fail());
return num;
}
double ResultsCheckerEntry::GetTime(const char* which) const {
double val = GetAs< double >(which);
auto unit = Get("time_unit");
CHECK(unit);
if(*unit == "ns") {
return val * 1.e-9;
} else if(*unit == "us") {
return val * 1.e-6;
} else if(*unit == "ms") {
return val * 1.e-3;
} else if(*unit == "s") {
return val;
} else {
CHECK(1 == 0) << "unknown time unit: " << *unit;
return 0;
}
}
// ========================================================================= // // ========================================================================= //
// -------------------------- Public API Definitions------------------------ // // -------------------------- Public API Definitions------------------------ //
// ========================================================================= // // ========================================================================= //
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment