mirror of https://github.com/google/benchmark.git
Make Results::GetTime() receive an enum.
This commit is contained in:
parent
62b1dd9c4a
commit
64b5f3ff2d
|
@ -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>
|
||||
|
|
|
@ -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") {
|
||||
|
|
Loading…
Reference in New Issue