Fixed compiler warnings (#1697)

* fixed warnings
used proper math functions

* ran clang format

* used a more up-to-date clang-format

* space twedling

* reveretd CMakeLists.txt
This commit is contained in:
Tiago Freire 2023-11-10 11:09:50 +01:00 committed by GitHub
parent b40db86945
commit a543fcd410
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 29 additions and 20 deletions

View File

@ -108,7 +108,7 @@ BenchmarkReporter::Run CreateRunReport(
report.memory_result = memory_result;
report.allocs_per_iter =
memory_iterations ? static_cast<double>(memory_result->num_allocs) /
memory_iterations
static_cast<double>(memory_iterations)
: 0;
}

View File

@ -37,12 +37,14 @@ BigOFunc* FittingCurve(BigO complexity) {
return [](IterationCount n) -> double { return std::pow(n, 3); };
case oLogN:
/* Note: can't use log2 because Android's GNU STL lacks it */
return
[](IterationCount n) { return kLog2E * log(static_cast<double>(n)); };
return [](IterationCount n) {
return kLog2E * std::log(static_cast<double>(n));
};
case oNLogN:
/* Note: can't use log2 because Android's GNU STL lacks it */
return [](IterationCount n) {
return kLog2E * n * log(static_cast<double>(n));
return kLog2E * static_cast<double>(n) *
std::log(static_cast<double>(n));
};
case o1:
default:
@ -105,12 +107,12 @@ LeastSq MinimalLeastSq(const std::vector<int64_t>& n,
double rms = 0.0;
for (size_t i = 0; i < n.size(); ++i) {
double fit = result.coef * fitting_curve(n[i]);
rms += pow((time[i] - fit), 2);
rms += std::pow((time[i] - fit), 2);
}
// Normalized RMS by the mean of the observed values
double mean = sigma_time / n.size();
result.rms = sqrt(rms / n.size()) / mean;
double mean = sigma_time / static_cast<double>(n.size());
result.rms = std::sqrt(rms / static_cast<double>(n.size())) / mean;
return result;
}
@ -171,8 +173,10 @@ std::vector<BenchmarkReporter::Run> ComputeBigO(
BM_CHECK_GT(run.complexity_n, 0)
<< "Did you forget to call SetComplexityN?";
n.push_back(run.complexity_n);
real_time.push_back(run.real_accumulated_time / run.iterations);
cpu_time.push_back(run.cpu_accumulated_time / run.iterations);
real_time.push_back(run.real_accumulated_time /
static_cast<double>(run.iterations));
cpu_time.push_back(run.cpu_accumulated_time /
static_cast<double>(run.iterations));
}
LeastSq result_cpu;

View File

@ -27,10 +27,10 @@ double Finish(Counter const& c, IterationCount iterations, double cpu_time,
v /= num_threads;
}
if (c.flags & Counter::kIsIterationInvariant) {
v *= iterations;
v *= static_cast<double>(iterations);
}
if (c.flags & Counter::kAvgIterations) {
v /= iterations;
v /= static_cast<double>(iterations);
}
if (c.flags & Counter::kInvert) { // Invert is *always* last.

View File

@ -218,9 +218,10 @@ inline BENCHMARK_ALWAYS_INLINE int64_t Now() {
asm volatile("%0 = C15:14" : "=r"(pcycle));
return static_cast<double>(pcycle);
#else
// The soft failover to a generic implementation is automatic only for ARM.
// For other platforms the developer is expected to make an attempt to create
// a fast implementation and use generic version if nothing better is available.
// The soft failover to a generic implementation is automatic only for ARM.
// For other platforms the developer is expected to make an attempt to create
// a fast implementation and use generic version if nothing better is
// available.
#error You need to define CycleTimer for your OS and CPU
#endif
}

View File

@ -32,7 +32,7 @@ auto StatisticsSum = [](const std::vector<double>& v) {
double StatisticsMean(const std::vector<double>& v) {
if (v.empty()) return 0.0;
return StatisticsSum(v) * (1.0 / v.size());
return StatisticsSum(v) * (1.0 / static_cast<double>(v.size()));
}
double StatisticsMedian(const std::vector<double>& v) {
@ -71,8 +71,11 @@ double StatisticsStdDev(const std::vector<double>& v) {
// Sample standard deviation is undefined for n = 1
if (v.size() == 1) return 0.0;
const double avg_squares = SumSquares(v) * (1.0 / v.size());
return Sqrt(v.size() / (v.size() - 1.0) * (avg_squares - Sqr(mean)));
const double avg_squares =
SumSquares(v) * (1.0 / static_cast<double>(v.size()));
return Sqrt(static_cast<double>(v.size()) /
(static_cast<double>(v.size()) - 1.0) *
(avg_squares - Sqr(mean)));
}
double StatisticsCV(const std::vector<double>& v) {

View File

@ -655,7 +655,7 @@ double GetCPUCyclesPerSecond(CPUInfo::Scaling scaling) {
&freq)) {
// The value is in kHz (as the file name suggests). For example, on a
// 2GHz warpstation, the file contains the value "2000000".
return freq * 1000.0;
return static_cast<double>(freq) * 1000.0;
}
const double error_value = -1;

View File

@ -102,7 +102,8 @@ double MakeTime(thread_basic_info_data_t const& info) {
#endif
#if defined(CLOCK_PROCESS_CPUTIME_ID) || defined(CLOCK_THREAD_CPUTIME_ID)
double MakeTime(struct timespec const& ts) {
return ts.tv_sec + (static_cast<double>(ts.tv_nsec) * 1e-9);
return static_cast<double>(ts.tv_sec) +
(static_cast<double>(ts.tv_nsec) * 1e-9);
}
#endif

View File

@ -175,7 +175,7 @@ BENCHMARK(BM_Complexity_O_N_log_N)
->RangeMultiplier(2)
->Range(1 << 10, 1 << 16)
->Complexity([](benchmark::IterationCount n) {
return kLog2E * static_cast<double>(n) * log(static_cast<double>(n));
return kLog2E * static_cast<double>(n) * std::log(static_cast<double>(n));
});
BENCHMARK(BM_Complexity_O_N_log_N)
->RangeMultiplier(2)