mirror of
https://github.com/google/benchmark.git
synced 2025-04-10 11:30:17 +08:00
ResultsCheckerEntry: add more getter functions.
This commit is contained in:
parent
2a8d0dd1b1
commit
1826feb164
@ -73,9 +73,26 @@ struct ResultsCheckerEntry {
|
||||
std::map< std::string, std::string > values;
|
||||
ResultsCheckFn check_fn;
|
||||
|
||||
// int NumThreads() const; // TODO
|
||||
// double duration_real_time() const {} // TODO
|
||||
// double duration_cpu_time() const {} // TODO
|
||||
int NumThreads() const {
|
||||
auto pos = name.find_last_of("/threads:");
|
||||
if(pos == name.npos) return 1;
|
||||
auto end = name.find_last_of('/', 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
|
||||
double DurationRealTime() const {
|
||||
return GetAs< double >("iterations") * GetTime("real_time");
|
||||
}
|
||||
// get the cpu_time duration of the benchmark in seconds
|
||||
double DurationCPUTime() const {
|
||||
return GetAs< double >("iterations") * GetTime("cpu_time");
|
||||
}
|
||||
|
||||
// get the string for a result by name, or nullptr if the name
|
||||
// is not found
|
||||
@ -105,6 +122,25 @@ struct ResultsCheckerEntry {
|
||||
T tval = static_cast< T >(dval);
|
||||
return tval;
|
||||
}
|
||||
|
||||
// get cpu_time or real_time in seconds
|
||||
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;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
#define _CHECK_RESULT_VALUE(entry, getfn, var_type, var_name, relationship, value) \
|
||||
|
Loading…
Reference in New Issue
Block a user