Make Results::GetTime() receive an enum.

This commit is contained in:
Joao Paulo Magalhaes 2017-05-01 22:32:40 +01:00
parent 62b1dd9c4a
commit 64b5f3ff2d
2 changed files with 14 additions and 8 deletions

View File

@ -96,13 +96,20 @@ struct Results {
int NumThreads() const;
// get the real_time duration of the benchmark in seconds
typedef enum { kCpuTime, kRealTime } BenchmarkTime;
// get cpu_time or real_time in seconds
double GetTime(BenchmarkTime which) const;
// get the real_time duration of the benchmark in seconds.
// it is better to use fuzzy float checks for this, as the float
// ASCII formatting is lossy.
double DurationRealTime() const {
return GetAs< double >("iterations") * GetTime("real_time");
return GetAs< double >("iterations") * GetTime(kRealTime);
}
// get the cpu_time duration of the benchmark in seconds
double DurationCPUTime() const {
return GetAs< double >("iterations") * GetTime("cpu_time");
return GetAs< double >("iterations") * GetTime(kCpuTime);
}
// get the string for a result by name, or nullptr if the name
@ -126,9 +133,6 @@ struct Results {
T tval = static_cast< T >(dval);
return tval;
}
// get cpu_time or real_time in seconds
double GetTime(const char* which) const;
};
template <class T>

View File

@ -303,8 +303,10 @@ int Results::NumThreads() const {
return num;
}
double Results::GetTime(const char* which) const {
double val = GetAs< double >(which);
double Results::GetTime(BenchmarkTime which) const {
CHECK(which == kCpuTime || which == kRealTime);
const char *which_str = which == kCpuTime ? "cpu_time" : "real_time";
double val = GetAs< double >(which_str);
auto unit = Get("time_unit");
CHECK(unit);
if(*unit == "ns") {