Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/benchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ void State::ResumeTiming() {
void State::SkipWithMessage(const std::string& msg) {
skipped_ = internal::SkippedWithMessage;
{
MutexLock l(manager_->GetBenchmarkMutex());
MutexLock const l(manager_->GetBenchmarkMutex());
if (internal::NotSkipped == manager_->results.skipped_) {
manager_->results.skip_message_ = msg;
manager_->results.skipped_ = skipped_;
Expand All @@ -305,7 +305,7 @@ void State::SkipWithMessage(const std::string& msg) {
void State::SkipWithError(const std::string& msg) {
skipped_ = internal::SkippedWithError;
{
MutexLock l(manager_->GetBenchmarkMutex());
MutexLock const l(manager_->GetBenchmarkMutex());
if (internal::NotSkipped == manager_->results.skipped_) {
manager_->results.skip_message_ = msg;
manager_->results.skipped_ = skipped_;
Expand All @@ -322,7 +322,7 @@ void State::SetIterationTime(double seconds) {
}

void State::SetLabel(const std::string& label) {
MutexLock l(manager_->GetBenchmarkMutex());
MutexLock const l(manager_->GetBenchmarkMutex());
manager_->results.report_label_ = label;
}

Expand Down Expand Up @@ -452,7 +452,7 @@ void RunBenchmarks(const std::vector<BenchmarkInstance>& benchmarks,
}
benchmarks_with_threads += static_cast<int>(benchmark.threads() > 1);
runners.emplace_back(benchmark, &perfcounters, reports_for_family);
int num_repeats_of_this_instance = runners.back().GetNumRepeats();
int const num_repeats_of_this_instance = runners.back().GetNumRepeats();
num_repetitions_total +=
static_cast<size_t>(num_repeats_of_this_instance);
if (reports_for_family != nullptr) {
Expand Down Expand Up @@ -489,7 +489,7 @@ void RunBenchmarks(const std::vector<BenchmarkInstance>& benchmarks,
std::shuffle(repetition_indices.begin(), repetition_indices.end(), g);
}

for (size_t repetition_index : repetition_indices) {
for (size_t const repetition_index : repetition_indices) {
internal::BenchmarkRunner& runner = runners[repetition_index];
runner.DoOneRepetition();
if (runner.HasRepeatsRemaining()) {
Expand Down Expand Up @@ -823,7 +823,7 @@ void ParseCommandLineFlags(int* argc, char** argv) {
} // end namespace

int InitializeStreams() {
static std::ios_base::Init init;
static std::ios_base::Init const init;
return 0;
}

Expand Down
8 changes: 4 additions & 4 deletions src/benchmark_api_internal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,16 @@ State BenchmarkInstance::Run(

void BenchmarkInstance::Setup() const {
if (setup_ != nullptr) {
State st(name_.function_name, /*iters*/ 1, args_, /*thread_id*/ 0, threads_,
nullptr, nullptr, nullptr, nullptr);
State const st(name_.function_name, /*iters*/ 1, args_, /*thread_id*/ 0,
threads_, nullptr, nullptr, nullptr, nullptr);
setup_(st);
}
}

void BenchmarkInstance::Teardown() const {
if (teardown_ != nullptr) {
State st(name_.function_name, /*iters*/ 1, args_, /*thread_id*/ 0, threads_,
nullptr, nullptr, nullptr, nullptr);
State const st(name_.function_name, /*iters*/ 1, args_, /*thread_id*/ 0,
threads_, nullptr, nullptr, nullptr, nullptr);
teardown_(st);
}
}
Expand Down
16 changes: 8 additions & 8 deletions src/benchmark_register.cc
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,14 @@ BenchmarkFamilies* BenchmarkFamilies::GetInstance() {

size_t BenchmarkFamilies::AddBenchmark(
std::unique_ptr<benchmark::Benchmark> family) {
MutexLock l(mutex_);
size_t index = families_.size();
MutexLock const l(mutex_);
size_t const index = families_.size();
families_.push_back(std::move(family));
return index;
}

void BenchmarkFamilies::ClearBenchmarks() {
MutexLock l(mutex_);
MutexLock const l(mutex_);
families_.clear();
families_.shrink_to_fit();
}
Expand Down Expand Up @@ -140,9 +140,9 @@ bool BenchmarkFamilies::FindBenchmarks(

int next_family_index = 0;

MutexLock l(mutex_);
MutexLock const l(mutex_);
for (std::unique_ptr<benchmark::Benchmark>& family : families_) {
int family_index = next_family_index;
int const family_index = next_family_index;
int per_family_instance_index = 0;

// Family was deleted or benchmark doesn't match
Expand Down Expand Up @@ -172,7 +172,7 @@ bool BenchmarkFamilies::FindBenchmarks(
}

for (auto const& args : family->args_) {
for (int num_threads : *thread_counts) {
for (int const num_threads : *thread_counts) {
BenchmarkInstance instance(family.get(), family_index,
per_family_instance_index, args,
num_threads);
Expand Down Expand Up @@ -264,7 +264,7 @@ Benchmark* Benchmark::Range(int64_t start, int64_t limit) {
std::vector<int64_t> arglist;
internal::AddRange(&arglist, start, limit, range_multiplier_);

for (int64_t i : arglist) {
for (int64_t const i : arglist) {
args_.push_back({i});
}
return this;
Expand Down Expand Up @@ -517,7 +517,7 @@ int Benchmark::ArgsCnt() const {

const char* Benchmark::GetArgName(int arg) const {
BM_CHECK_GE(arg, 0);
size_t uarg = static_cast<size_t>(arg);
size_t const uarg = static_cast<size_t>(arg);
BM_CHECK_LT(uarg, arg_names_.size());
return arg_names_[uarg].c_str();
}
Expand Down
24 changes: 12 additions & 12 deletions src/benchmark_runner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ BenchmarkReporter::Run CreateRunReport(
report.repetition_index = repetition_index;
report.repetitions = repeats;

if (report.skipped == 0u) {
if (report.skipped == 0U) {
if (b.use_manual_time()) {
report.real_accumulated_time = results.manual_time_used;
} else {
Expand Down Expand Up @@ -152,13 +152,13 @@ void RunInThread(const BenchmarkInstance* b, IterationCount iters,

State st = b->Run(iters, thread_id, &timer, manager,
perf_counters_measurement, profiler_manager_);
if (!(st.skipped() || st.iterations() >= st.max_iterations)) {
if (!st.skipped() && st.iterations() < st.max_iterations) {
st.SkipWithError(
"The benchmark didn't run, nor was it explicitly skipped. Please call "
"'SkipWithXXX` in your benchmark as appropriate.");
}
{
MutexLock l(manager->GetBenchmarkMutex());
MutexLock const l(manager->GetBenchmarkMutex());
internal::ThreadManager::Result& results = manager->results;
results.iterations += st.iterations();
results.cpu_time_used += timer.cpu_time_used();
Expand Down Expand Up @@ -244,7 +244,7 @@ BenchTimeType ParseBenchMinTime(const std::string& value) {
char* p_end = nullptr;
// Reset errno before it's changed by strtol.
errno = 0;
IterationCount num_iters = std::strtol(value.c_str(), &p_end, 10);
IterationCount const num_iters = std::strtol(value.c_str(), &p_end, 10);

// After a valid parse, p_end should have been set to
// point to the 'x' suffix.
Expand All @@ -257,7 +257,7 @@ BenchTimeType ParseBenchMinTime(const std::string& value) {
return ret;
}

bool has_suffix = value.back() == 's';
bool const has_suffix = value.back() == 's';
if (!has_suffix) {
BM_VLOG(0) << "Value passed to --benchmark_min_time should have a suffix. "
"Eg., `30s` for 30-seconds.";
Expand All @@ -266,7 +266,7 @@ BenchTimeType ParseBenchMinTime(const std::string& value) {
char* p_end = nullptr;
// Reset errno before it's changed by strtod.
errno = 0;
double min_time = std::strtod(value.c_str(), &p_end);
double const min_time = std::strtod(value.c_str(), &p_end);

// After a successful parse, p_end should point to the suffix 's',
// or the end of the string if the suffix was omitted.
Expand Down Expand Up @@ -321,10 +321,10 @@ BenchmarkRunner::BenchmarkRunner(
if (b.aggregation_report_mode() != internal::ARM_Unspecified) {
run_results.display_report_aggregates_only =
((b.aggregation_report_mode() &
internal::ARM_DisplayReportAggregatesOnly) != 0u);
internal::ARM_DisplayReportAggregatesOnly) != 0U);
run_results.file_report_aggregates_only =
((b.aggregation_report_mode() &
internal::ARM_FileReportAggregatesOnly) != 0u);
internal::ARM_FileReportAggregatesOnly) != 0U);
BM_CHECK(FLAGS_benchmark_perf_counters.empty() ||
(perf_counters_measurement_ptr->num_counters() == 0))
<< "Perf counters were requested but could not be set up.";
Expand All @@ -345,7 +345,7 @@ BenchmarkRunner::IterationResults BenchmarkRunner::DoNIterations() {
IterationResults i;
// Acquire the measurements/counters from the manager, UNDER THE LOCK!
{
MutexLock l(manager->GetBenchmarkMutex());
MutexLock const l(manager->GetBenchmarkMutex());
i.results = manager->results;
}

Expand Down Expand Up @@ -399,7 +399,7 @@ bool BenchmarkRunner::ShouldReportIterationResults(
// Determine if this run should be reported;
// Either it has run for a sufficient amount of time
// or because an error was reported.
return (i.results.skipped_ != 0u) || FLAGS_benchmark_dry_run ||
return (i.results.skipped_ != 0U) || FLAGS_benchmark_dry_run ||
i.iters >= kMaxIterations || // Too many iterations already.
i.seconds >=
GetMinTimeToApply() || // The elapsed time is large enough.
Expand Down Expand Up @@ -554,13 +554,13 @@ void BenchmarkRunner::DoOneRepetition() {
}

// Ok, now actually report.
BenchmarkReporter::Run report =
BenchmarkReporter::Run const report =
CreateRunReport(b, i.results, memory_iterations, memory_result, i.seconds,
num_repetitions_done, repeats);

if (reports_for_family != nullptr) {
++reports_for_family->num_runs_done;
if (report.skipped == 0u) {
if (report.skipped == 0U) {
reports_for_family->Runs.push_back(report);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/colorprint.cc
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ std::string FormatString(const char* msg, va_list args) {
}
// we did not provide a long enough buffer on our first attempt.
size = static_cast<size_t>(ret) + 1; // + 1 for the null byte
std::unique_ptr<char[]> buff(new char[size]);
std::unique_ptr<char[]> const buff(new char[size]);
va_list args_cp2;
va_copy(args_cp2, args);
ret = vsnprintf(buff.get(), size, msg, args_cp2);
Expand Down
4 changes: 2 additions & 2 deletions src/commandlineflags.cc
Original file line number Diff line number Diff line change
Expand Up @@ -308,9 +308,9 @@ bool IsFlag(const char* str, const char* flag) {
BENCHMARK_EXPORT
bool IsTruthyFlagValue(const std::string& value) {
if (value.size() == 1) {
char v = value[0];
char const v = value[0];
return isalnum(v) &&
!(v == '0' || v == 'f' || v == 'F' || v == 'n' || v == 'N');
v != '0' && v != 'f' && v != 'F' && v != 'n' && v != 'N';
}
if (!value.empty()) {
std::string value_lower(value);
Expand Down
13 changes: 7 additions & 6 deletions src/complexity.cc
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ LeastSq MinimalLeastSq(const std::vector<ComplexityN>& n,

// Calculate least square fitting parameter
for (size_t i = 0; i < n.size(); ++i) {
double gn_i = fitting_curve(n[i]);
double const gn_i = fitting_curve(n[i]);
sigma_gn_squared += gn_i * gn_i;
sigma_time += time[i];
sigma_time_gn += time[i] * gn_i;
Expand All @@ -109,12 +109,12 @@ LeastSq MinimalLeastSq(const std::vector<ComplexityN>& n,
// Calculate RMS
double rms = 0.0;
for (size_t i = 0; i < n.size(); ++i) {
double fit = result.coef * fitting_curve(n[i]);
double const fit = result.coef * fitting_curve(n[i]);
rms += std::pow((time[i] - fit), 2);
}

// Normalized RMS by the mean of the observed values
double mean = sigma_time / static_cast<double>(n.size());
double const mean = sigma_time / static_cast<double>(n.size());
result.rms = std::sqrt(rms / static_cast<double>(n.size())) / mean;

return result;
Expand All @@ -137,15 +137,16 @@ LeastSq MinimalLeastSq(const std::vector<ComplexityN>& n,
LeastSq best_fit;

if (complexity == oAuto) {
std::vector<BigO> fit_curves = {oLogN, oN, oNLogN, oNSquared, oNCubed};
std::vector<BigO> const fit_curves = {oLogN, oN, oNLogN, oNSquared,
oNCubed};

// Take o1 as default best fitting curve
best_fit = MinimalLeastSq(n, time, FittingCurve(o1));
best_fit.complexity = o1;

// Compute all possible fitting curves and stick to the best one
for (const auto& fit : fit_curves) {
LeastSq current_fit = MinimalLeastSq(n, time, FittingCurve(fit));
LeastSq const current_fit = MinimalLeastSq(n, time, FittingCurve(fit));
if (current_fit.rms < best_fit.rms) {
best_fit = current_fit;
best_fit.complexity = fit;
Expand Down Expand Up @@ -235,7 +236,7 @@ std::vector<BenchmarkReporter::Run> ComputeBigO(
// should not be multiplied at all. So, here, we _divide_ it by the
// multiplier so that when it is multiplied later the result is the
// correct one.
double multiplier = GetTimeUnitMultiplier(reports[0].time_unit);
double const multiplier = GetTimeUnitMultiplier(reports[0].time_unit);

// Only add label to mean/stddev if it is same for all runs
Run rms;
Expand Down
14 changes: 9 additions & 5 deletions src/console_reporter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ void ConsoleReporter::PrintHeader(const Run& run) {
str += " UserCounters...";
}
}
std::string line = std::string(str.length(), '-');
std::string const line = std::string(str.length(), '-');
GetOutputStream() << line << "\n" << str << "\n" << line << "\n";
}

Expand All @@ -99,16 +99,18 @@ void ConsoleReporter::ReportRuns(const std::vector<Run>& reports) {
}
}

namespace {

PRINTF_FORMAT_STRING_FUNC(3, 4)
static void IgnoreColorPrint(std::ostream& out, LogColor /*unused*/,
const char* fmt, ...) {
void IgnoreColorPrint(std::ostream& out, LogColor /*unused*/, const char* fmt,
...) {
va_list args;
va_start(args, fmt);
out << FormatString(fmt, args);
va_end(args);
}

static std::string FormatTime(double time) {
std::string FormatTime(double time) {
// For the time columns of the console printer 13 digits are reserved. One of
// them is a space and max two of them are the time unit (e.g ns). That puts
// us at 10 digits usable for the number.
Expand All @@ -130,6 +132,8 @@ static std::string FormatTime(double time) {
return FormatString("%10.0f", time);
}

} // namespace

BENCHMARK_EXPORT
void ConsoleReporter::PrintRunData(const Run& result) {
typedef void(PrinterFn)(std::ostream&, LogColor, const char*, ...);
Expand Down Expand Up @@ -160,7 +164,7 @@ void ConsoleReporter::PrintRunData(const Run& result) {
const std::string cpu_time_str = FormatTime(cpu_time);

if (result.report_big_o) {
std::string big_o = GetBigOString(result.complexity);
std::string const big_o = GetBigOString(result.complexity);
printer(Out, COLOR_YELLOW, "%10.2f %-4s %10.2f %-4s ", real_time,
big_o.c_str(), cpu_time, big_o.c_str());
} else if (result.report_rms) {
Expand Down
12 changes: 6 additions & 6 deletions src/counter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

#include "counter.h"

#include <algorithm>

namespace benchmark {
namespace internal {

Expand Down Expand Up @@ -74,12 +76,10 @@ bool SameNames(UserCounters const& l, UserCounters const& r) {
if (l.size() != r.size()) {
return false;
}
for (auto const& c : l) {
if (r.find(c.first) == r.end()) {
return false;
}
}
return true;
return std::all_of(l.begin(), l.end(),
[&r](const UserCounters::value_type& c) {
return r.find(c.first) != r.end();
});
}

} // end namespace internal
Expand Down
4 changes: 2 additions & 2 deletions src/csv_reporter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const std::vector<const char*> elements = {
std::string CsvEscape(const std::string& s) {
std::string tmp;
tmp.reserve(s.size() + 2);
for (char c : s) {
for (char const c : s) {
switch (c) {
case '"':
tmp += "\"\"";
Expand Down Expand Up @@ -112,7 +112,7 @@ BENCHMARK_EXPORT
void CSVReporter::PrintRunData(const Run& run) {
std::ostream& Out = GetOutputStream();
Out << CsvEscape(run.benchmark_name()) << ",";
if (run.skipped != 0u) {
if (run.skipped != 0U) {
Out << std::string(elements.size() - 3, ',');
Out << std::boolalpha << (internal::SkippedWithError == run.skipped) << ",";
Out << CsvEscape(run.skip_message) << "\n";
Expand Down
Loading
Loading