mirror of
https://github.com/google/benchmark.git
synced 2025-03-27 20:40:40 +08:00
clang-format Google on {src/,include/} (#1280)
This commit is contained in:
parent
431abd149f
commit
fcef4fb669
@ -245,8 +245,7 @@ BENCHMARK(BM_test)->Unit(benchmark::kMillisecond);
|
||||
#define BENCHMARK_DISABLE_DEPRECATED_WARNING \
|
||||
_Pragma("GCC diagnostic push") \
|
||||
_Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
|
||||
#define BENCHMARK_RESTORE_DEPRECATED_WARNING \
|
||||
_Pragma("GCC diagnostic pop")
|
||||
#define BENCHMARK_RESTORE_DEPRECATED_WARNING _Pragma("GCC diagnostic pop")
|
||||
#else
|
||||
#define BENCHMARK_BUILTIN_EXPECT(x, y) x
|
||||
#define BENCHMARK_DEPRECATED_MSG(msg)
|
||||
@ -1440,11 +1439,7 @@ struct CPUInfo {
|
||||
int num_sharing;
|
||||
};
|
||||
|
||||
enum Scaling {
|
||||
UNKNOWN,
|
||||
ENABLED,
|
||||
DISABLED
|
||||
};
|
||||
enum Scaling { UNKNOWN, ENABLED, DISABLED };
|
||||
|
||||
int num_cpus;
|
||||
Scaling scaling;
|
||||
@ -1704,7 +1699,6 @@ class BENCHMARK_DEPRECATED_MSG(
|
||||
std::set<std::string> user_counter_names_;
|
||||
};
|
||||
|
||||
|
||||
inline const char* GetTimeUnitString(TimeUnit unit) {
|
||||
switch (unit) {
|
||||
case kSecond:
|
||||
@ -1745,8 +1739,7 @@ inline double GetTimeUnitMultiplier(TimeUnit unit) {
|
||||
std::vector<int64_t> CreateRange(int64_t lo, int64_t hi, int multi);
|
||||
|
||||
// Creates a list of integer values for the given range and step.
|
||||
std::vector<int64_t> CreateDenseRange(int64_t start, int64_t limit,
|
||||
int step);
|
||||
std::vector<int64_t> CreateDenseRange(int64_t start, int64_t limit, int step);
|
||||
|
||||
} // namespace benchmark
|
||||
|
||||
|
@ -617,9 +617,7 @@ void Initialize(int* argc, char** argv) {
|
||||
internal::LogLevel() = FLAGS_v;
|
||||
}
|
||||
|
||||
void Shutdown() {
|
||||
delete internal::global_context;
|
||||
}
|
||||
void Shutdown() { delete internal::global_context; }
|
||||
|
||||
bool ReportUnrecognizedArguments(int argc, char** argv) {
|
||||
for (int i = 1; i < argc; ++i) {
|
||||
|
@ -466,8 +466,7 @@ std::vector<int64_t> CreateRange(int64_t lo, int64_t hi, int multi) {
|
||||
return args;
|
||||
}
|
||||
|
||||
std::vector<int64_t> CreateDenseRange(int64_t start, int64_t limit,
|
||||
int step) {
|
||||
std::vector<int64_t> CreateDenseRange(int64_t start, int64_t limit, int step) {
|
||||
BM_CHECK_LE(start, limit);
|
||||
std::vector<int64_t> args;
|
||||
for (int64_t arg = start; arg <= limit; arg += step) {
|
||||
|
@ -12,8 +12,8 @@ namespace internal {
|
||||
// Append the powers of 'mult' in the closed interval [lo, hi].
|
||||
// Returns iterator to the start of the inserted range.
|
||||
template <typename T>
|
||||
typename std::vector<T>::iterator
|
||||
AddPowers(std::vector<T>* dst, T lo, T hi, int mult) {
|
||||
typename std::vector<T>::iterator AddPowers(std::vector<T>* dst, T lo, T hi,
|
||||
int mult) {
|
||||
BM_CHECK_GE(lo, 0);
|
||||
BM_CHECK_GE(hi, lo);
|
||||
BM_CHECK_GE(mult, 2);
|
||||
|
@ -25,8 +25,8 @@
|
||||
#include "internal_macros.h"
|
||||
|
||||
#ifdef BENCHMARK_OS_WINDOWS
|
||||
#include <windows.h>
|
||||
#include <io.h>
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#endif // BENCHMARK_OS_WINDOWS
|
||||
|
@ -248,8 +248,7 @@ bool ParseStringFlag(const char* str, const char* flag, std::string* value) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ParseKeyValueFlag(
|
||||
const char* str, const char* flag,
|
||||
bool ParseKeyValueFlag(const char* str, const char* flag,
|
||||
std::map<std::string, std::string>* value) {
|
||||
const char* const value_str = ParseFlagValue(str, flag, false);
|
||||
|
||||
|
@ -15,12 +15,13 @@
|
||||
// Source project : https://github.com/ismaelJimenez/cpp.leastsq
|
||||
// Adapted to be used with google benchmark
|
||||
|
||||
#include "benchmark/benchmark.h"
|
||||
#include "complexity.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
|
||||
#include "benchmark/benchmark.h"
|
||||
#include "check.h"
|
||||
#include "complexity.h"
|
||||
|
||||
namespace benchmark {
|
||||
|
||||
|
@ -53,7 +53,8 @@ bool ConsoleReporter::ReportContext(const Context& context) {
|
||||
}
|
||||
|
||||
void ConsoleReporter::PrintHeader(const Run& run) {
|
||||
std::string str = FormatString("%-*s %13s %15s %12s", static_cast<int>(name_field_width_),
|
||||
std::string str =
|
||||
FormatString("%-*s %13s %15s %12s", static_cast<int>(name_field_width_),
|
||||
"Benchmark", "Time", "CPU", "Iterations");
|
||||
if (!run.counters.empty()) {
|
||||
if (output_options_ & OO_Tabular) {
|
||||
@ -97,7 +98,6 @@ static void IgnoreColorPrint(std::ostream& out, LogColor, const char* fmt,
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
|
||||
static std::string FormatTime(double time) {
|
||||
// Align decimal places...
|
||||
if (time < 1.0) {
|
||||
@ -115,8 +115,9 @@ static std::string FormatTime(double time) {
|
||||
void ConsoleReporter::PrintRunData(const Run& result) {
|
||||
typedef void(PrinterFn)(std::ostream&, LogColor, const char*, ...);
|
||||
auto& Out = GetOutputStream();
|
||||
PrinterFn* printer = (output_options_ & OO_Color) ?
|
||||
static_cast<PrinterFn*>(ColorPrintf) : IgnoreColorPrint;
|
||||
PrinterFn* printer = (output_options_ & OO_Color)
|
||||
? static_cast<PrinterFn*>(ColorPrintf)
|
||||
: IgnoreColorPrint;
|
||||
auto name_color =
|
||||
(result.report_big_o || result.report_rms) ? COLOR_BLUE : COLOR_GREEN;
|
||||
printer(Out, name_color, "%-*s ", name_field_width_,
|
||||
@ -134,19 +135,18 @@ void ConsoleReporter::PrintRunData(const Run& result) {
|
||||
const std::string real_time_str = FormatTime(real_time);
|
||||
const std::string cpu_time_str = FormatTime(cpu_time);
|
||||
|
||||
|
||||
if (result.report_big_o) {
|
||||
std::string 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());
|
||||
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) {
|
||||
printer(Out, COLOR_YELLOW, "%10.0f %-4s %10.0f %-4s ", real_time * 100, "%",
|
||||
cpu_time * 100, "%");
|
||||
} else if (result.run_type != Run::RT_Aggregate ||
|
||||
result.aggregate_unit == StatisticUnit::kTime) {
|
||||
const char* timeLabel = GetTimeUnitString(result.time_unit);
|
||||
printer(Out, COLOR_YELLOW, "%s %-4s %s %-4s ", real_time_str.c_str(), timeLabel,
|
||||
cpu_time_str.c_str(), timeLabel);
|
||||
printer(Out, COLOR_YELLOW, "%s %-4s %s %-4s ", real_time_str.c_str(),
|
||||
timeLabel, cpu_time_str.c_str(), timeLabel);
|
||||
} else {
|
||||
assert(result.aggregate_unit == StatisticUnit::kPercentage);
|
||||
printer(Out, COLOR_YELLOW, "%10.2f %-4s %10.2f %-4s ",
|
||||
@ -159,8 +159,8 @@ void ConsoleReporter::PrintRunData(const Run& result) {
|
||||
}
|
||||
|
||||
for (auto& c : result.counters) {
|
||||
const std::size_t cNameLen = std::max(std::string::size_type(10),
|
||||
c.first.length());
|
||||
const std::size_t cNameLen =
|
||||
std::max(std::string::size_type(10), c.first.length());
|
||||
std::string s;
|
||||
const char* unit = "";
|
||||
if (result.run_type == Run::RT_Aggregate &&
|
||||
|
@ -12,9 +12,6 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "benchmark/benchmark.h"
|
||||
#include "complexity.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstdint>
|
||||
#include <iostream>
|
||||
@ -22,7 +19,9 @@
|
||||
#include <tuple>
|
||||
#include <vector>
|
||||
|
||||
#include "benchmark/benchmark.h"
|
||||
#include "check.h"
|
||||
#include "complexity.h"
|
||||
#include "string_util.h"
|
||||
#include "timers.h"
|
||||
|
||||
@ -42,8 +41,12 @@ std::string CsvEscape(const std::string & s) {
|
||||
tmp.reserve(s.size() + 2);
|
||||
for (char c : s) {
|
||||
switch (c) {
|
||||
case '"' : tmp += "\"\""; break;
|
||||
default : tmp += c; break;
|
||||
case '"':
|
||||
tmp += "\"\"";
|
||||
break;
|
||||
default:
|
||||
tmp += c;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return '"' + tmp + '"';
|
||||
|
@ -317,6 +317,7 @@ void JSONReporter::PrintRunData(Run const& run) {
|
||||
out << '\n';
|
||||
}
|
||||
|
||||
const int64_t MemoryManager::TombstoneValue = std::numeric_limits<int64_t>::max();
|
||||
const int64_t MemoryManager::TombstoneValue =
|
||||
std::numeric_limits<int64_t>::max();
|
||||
|
||||
} // end namespace benchmark
|
||||
|
@ -12,19 +12,17 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "benchmark/benchmark.h"
|
||||
#include "timers.h"
|
||||
|
||||
#include <cstdlib>
|
||||
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <tuple>
|
||||
#include <vector>
|
||||
|
||||
#include "benchmark/benchmark.h"
|
||||
#include "check.h"
|
||||
#include "string_util.h"
|
||||
#include "timers.h"
|
||||
|
||||
namespace benchmark {
|
||||
namespace internal {
|
||||
|
@ -43,8 +43,7 @@ void SleepForMicroseconds(int microseconds) {
|
||||
// argument is greater than 1000000.
|
||||
div_t sleepTime = div(microseconds, kNumMicrosPerSecond);
|
||||
int seconds = sleepTime.quot;
|
||||
while (seconds != 0)
|
||||
seconds = sleep(seconds);
|
||||
while (seconds != 0) seconds = sleep(seconds);
|
||||
while (usleep(sleepTime.rem) == -1 && errno == EINTR)
|
||||
;
|
||||
#else
|
||||
|
@ -13,15 +13,16 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "benchmark/benchmark.h"
|
||||
#include "statistics.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <numeric>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "benchmark/benchmark.h"
|
||||
#include "check.h"
|
||||
#include "statistics.h"
|
||||
|
||||
namespace benchmark {
|
||||
|
||||
|
@ -198,11 +198,10 @@ unsigned long stoul(const std::string& str, size_t* pos, int base) {
|
||||
|
||||
/* Check for errors and return */
|
||||
if (strtoulErrno == ERANGE) {
|
||||
throw std::out_of_range(
|
||||
"stoul failed: " + str + " is outside of range of unsigned long");
|
||||
throw std::out_of_range("stoul failed: " + str +
|
||||
" is outside of range of unsigned long");
|
||||
} else if (strEnd == strStart || strtoulErrno != 0) {
|
||||
throw std::invalid_argument(
|
||||
"stoul failed: " + str + " is not an integer");
|
||||
throw std::invalid_argument("stoul failed: " + str + " is not an integer");
|
||||
}
|
||||
if (pos != nullptr) {
|
||||
*pos = static_cast<size_t>(strEnd - strStart);
|
||||
@ -225,11 +224,10 @@ int stoi(const std::string& str, size_t* pos, int base) {
|
||||
|
||||
/* Check for errors and return */
|
||||
if (strtolErrno == ERANGE || long(int(result)) != result) {
|
||||
throw std::out_of_range(
|
||||
"stoul failed: " + str + " is outside of range of int");
|
||||
throw std::out_of_range("stoul failed: " + str +
|
||||
" is outside of range of int");
|
||||
} else if (strEnd == strStart || strtolErrno != 0) {
|
||||
throw std::invalid_argument(
|
||||
"stoul failed: " + str + " is not an integer");
|
||||
throw std::invalid_argument("stoul failed: " + str + " is not an integer");
|
||||
}
|
||||
if (pos != nullptr) {
|
||||
*pos = static_cast<size_t>(strEnd - strStart);
|
||||
@ -252,11 +250,10 @@ double stod(const std::string& str, size_t* pos) {
|
||||
|
||||
/* Check for errors and return */
|
||||
if (strtodErrno == ERANGE) {
|
||||
throw std::out_of_range(
|
||||
"stoul failed: " + str + " is outside of range of int");
|
||||
throw std::out_of_range("stoul failed: " + str +
|
||||
" is outside of range of int");
|
||||
} else if (strEnd == strStart || strtodErrno != 0) {
|
||||
throw std::invalid_argument(
|
||||
"stoul failed: " + str + " is not an integer");
|
||||
throw std::invalid_argument("stoul failed: " + str + " is not an integer");
|
||||
}
|
||||
if (pos != nullptr) {
|
||||
*pos = static_cast<size_t>(strEnd - strStart);
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#include "internal_macros.h"
|
||||
|
||||
namespace benchmark {
|
||||
@ -51,9 +52,9 @@ unsigned long stoul(const std::string& str, size_t* pos = nullptr,
|
||||
int stoi(const std::string& str, size_t* pos = nullptr, int base = 10);
|
||||
double stod(const std::string& str, size_t* pos = nullptr);
|
||||
#else
|
||||
using std::stoul;
|
||||
using std::stoi;
|
||||
using std::stod;
|
||||
using std::stoi;
|
||||
using std::stoul;
|
||||
#endif
|
||||
|
||||
} // end namespace benchmark
|
||||
|
@ -19,6 +19,7 @@
|
||||
#undef StrCat // Don't let StrCat in string_util.h be renamed to lstrcatA
|
||||
#include <versionhelpers.h>
|
||||
#include <windows.h>
|
||||
|
||||
#include <codecvt>
|
||||
#else
|
||||
#include <fcntl.h>
|
||||
@ -55,9 +56,9 @@
|
||||
#include <iostream>
|
||||
#include <iterator>
|
||||
#include <limits>
|
||||
#include <locale>
|
||||
#include <memory>
|
||||
#include <sstream>
|
||||
#include <locale>
|
||||
#include <utility>
|
||||
|
||||
#include "check.h"
|
||||
@ -224,7 +225,8 @@ CPUInfo::Scaling CpuScaling(int num_cpus) {
|
||||
for (int cpu = 0; cpu < num_cpus; ++cpu) {
|
||||
std::string governor_file =
|
||||
StrCat("/sys/devices/system/cpu/cpu", cpu, "/cpufreq/scaling_governor");
|
||||
if (ReadFromFile(governor_file, &res) && res != "performance") return CPUInfo::Scaling::ENABLED;
|
||||
if (ReadFromFile(governor_file, &res) && res != "performance")
|
||||
return CPUInfo::Scaling::ENABLED;
|
||||
}
|
||||
return CPUInfo::Scaling::DISABLED;
|
||||
#else
|
||||
@ -421,8 +423,7 @@ std::string GetSystemName() {
|
||||
const unsigned COUNT = MAX_COMPUTERNAME_LENGTH + 1;
|
||||
TCHAR hostname[COUNT] = {'\0'};
|
||||
DWORD DWCOUNT = COUNT;
|
||||
if (!GetComputerName(hostname, &DWCOUNT))
|
||||
return std::string("");
|
||||
if (!GetComputerName(hostname, &DWCOUNT)) return std::string("");
|
||||
#ifndef UNICODE
|
||||
str = std::string(hostname, DWCOUNT);
|
||||
#else
|
||||
@ -474,8 +475,7 @@ int GetNumCPUs() {
|
||||
// Returns -1 in case of a failure.
|
||||
int NumCPU = sysconf(_SC_NPROCESSORS_ONLN);
|
||||
if (NumCPU < 0) {
|
||||
fprintf(stderr,
|
||||
"sysconf(_SC_NPROCESSORS_ONLN) failed with error: %s\n",
|
||||
fprintf(stderr, "sysconf(_SC_NPROCESSORS_ONLN) failed with error: %s\n",
|
||||
strerror(errno));
|
||||
}
|
||||
return NumCPU;
|
||||
@ -498,7 +498,8 @@ int GetNumCPUs() {
|
||||
#if defined(__s390__)
|
||||
// s390 has another format in /proc/cpuinfo
|
||||
// it needs to be parsed differently
|
||||
if (SplitIdx != std::string::npos) value = ln.substr(Key.size()+1,SplitIdx-Key.size()-1);
|
||||
if (SplitIdx != std::string::npos)
|
||||
value = ln.substr(Key.size() + 1, SplitIdx - Key.size() - 1);
|
||||
#else
|
||||
if (SplitIdx != std::string::npos) value = ln.substr(SplitIdx + 1);
|
||||
#endif
|
||||
|
@ -13,6 +13,7 @@
|
||||
// limitations under the License.
|
||||
|
||||
#include "timers.h"
|
||||
|
||||
#include "internal_macros.h"
|
||||
|
||||
#ifdef BENCHMARK_OS_WINDOWS
|
||||
@ -125,8 +126,8 @@ double ProcessCPUUsage() {
|
||||
// syncronous system calls in Emscripten.
|
||||
return emscripten_get_now() * 1e-3;
|
||||
#elif defined(CLOCK_PROCESS_CPUTIME_ID) && !defined(BENCHMARK_OS_MACOSX)
|
||||
// FIXME We want to use clock_gettime, but its not available in MacOS 10.11. See
|
||||
// https://github.com/google/benchmark/pull/292
|
||||
// FIXME We want to use clock_gettime, but its not available in MacOS 10.11.
|
||||
// See https://github.com/google/benchmark/pull/292
|
||||
struct timespec spec;
|
||||
if (clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &spec) == 0)
|
||||
return MakeTime(spec);
|
||||
@ -149,8 +150,8 @@ double ThreadCPUUsage() {
|
||||
&user_time);
|
||||
return MakeTime(kernel_time, user_time);
|
||||
#elif defined(BENCHMARK_OS_MACOSX)
|
||||
// FIXME We want to use clock_gettime, but its not available in MacOS 10.11. See
|
||||
// https://github.com/google/benchmark/pull/292
|
||||
// FIXME We want to use clock_gettime, but its not available in MacOS 10.11.
|
||||
// See https://github.com/google/benchmark/pull/292
|
||||
mach_msg_type_number_t count = THREAD_BASIC_INFO_COUNT;
|
||||
thread_basic_info_data_t info;
|
||||
mach_port_t thread = pthread_mach_thread_np(pthread_self());
|
||||
@ -192,11 +193,14 @@ std::string LocalDateTimeString() {
|
||||
long int offset_minutes;
|
||||
char tz_offset_sign = '+';
|
||||
// tz_offset is set in one of three ways:
|
||||
// * strftime with %z - This either returns empty or the ISO 8601 time. The maximum length an
|
||||
// * strftime with %z - This either returns empty or the ISO 8601 time. The
|
||||
// maximum length an
|
||||
// ISO 8601 string can be is 7 (e.g. -03:30, plus trailing zero).
|
||||
// * snprintf with %c%02li:%02li - The maximum length is 41 (one for %c, up to 19 for %02li,
|
||||
// * snprintf with %c%02li:%02li - The maximum length is 41 (one for %c, up to
|
||||
// 19 for %02li,
|
||||
// one for :, up to 19 %02li, plus trailing zero).
|
||||
// * A fixed string of "-00:00". The maximum length is 7 (-00:00, plus trailing zero).
|
||||
// * A fixed string of "-00:00". The maximum length is 7 (-00:00, plus
|
||||
// trailing zero).
|
||||
//
|
||||
// Thus, the maximum size this needs to be is 41.
|
||||
char tz_offset[41];
|
||||
@ -224,7 +228,8 @@ std::string LocalDateTimeString() {
|
||||
tz_offset_sign = '-';
|
||||
}
|
||||
|
||||
tz_len = ::snprintf(tz_offset, sizeof(tz_offset), "%c%02li:%02li",
|
||||
tz_len =
|
||||
::snprintf(tz_offset, sizeof(tz_offset), "%c%02li:%02li",
|
||||
tz_offset_sign, offset_minutes / 100, offset_minutes % 100);
|
||||
BM_CHECK(tz_len == kTzOffsetLen);
|
||||
((void)tz_len); // Prevent unused variable warning in optimized build.
|
||||
@ -241,8 +246,8 @@ std::string LocalDateTimeString() {
|
||||
strncpy(tz_offset, "-00:00", kTzOffsetLen + 1);
|
||||
}
|
||||
|
||||
timestamp_len = std::strftime(storage, sizeof(storage), "%Y-%m-%dT%H:%M:%S",
|
||||
timeinfo_p);
|
||||
timestamp_len =
|
||||
std::strftime(storage, sizeof(storage), "%Y-%m-%dT%H:%M:%S", timeinfo_p);
|
||||
BM_CHECK(timestamp_len == kTimestampLen);
|
||||
// Prevent unused variable warning in optimized build.
|
||||
((void)kTimestampLen);
|
||||
|
Loading…
Reference in New Issue
Block a user