#ifndef BENCHMARK_BENCHMARK_H_
#define BENCHMARK_BENCHMARK_H_
#if __cplusplus >= 201103L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201103L)
#define BENCHMARK_HAS_CXX11
#endif
#if __cplusplus >= 201703L || \
(defined(_MSC_VER) && _MSC_VER >= 1911 && _MSVC_LANG >= 201703L)
#define BENCHMARK_HAS_CXX17
#endif
#include <stdint.h>
#include <algorithm>
#include <cassert>
#include <cstddef>
#include <iosfwd>
#include <limits>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>
#include "benchmark/export.h"
#if defined(BENCHMARK_HAS_CXX11)
#include <atomic>
#include <initializer_list>
#include <type_traits>
#include <utility>
#endif
#if defined(_MSC_VER)
#include <intrin.h>
#endif
#ifndef BENCHMARK_HAS_CXX11
#define BENCHMARK_DISALLOW_COPY_AND_ASSIGN …
#else
#define BENCHMARK_DISALLOW_COPY_AND_ASSIGN(TypeName) …
#endif
#ifdef BENCHMARK_HAS_CXX17
#define BENCHMARK_UNUSED …
#elif defined(__GNUC__) || defined(__clang__)
#define BENCHMARK_UNUSED …
#else
#define BENCHMARK_UNUSED
#endif
#if defined(__clang__)
#define BENCHMARK_DONT_OPTIMIZE …
#elif defined(__GNUC__) || defined(__GNUG__)
#define BENCHMARK_DONT_OPTIMIZE …
#else
#define BENCHMARK_DONT_OPTIMIZE
#endif
#if defined(__GNUC__) || defined(__clang__)
#define BENCHMARK_ALWAYS_INLINE …
#elif defined(_MSC_VER) && !defined(__clang__)
#define BENCHMARK_ALWAYS_INLINE …
#define __func__ __FUNCTION__
#else
#define BENCHMARK_ALWAYS_INLINE
#endif
#define BENCHMARK_INTERNAL_TOSTRING2(x) …
#define BENCHMARK_INTERNAL_TOSTRING(x) …
#if (defined(__GNUC__) && !defined(__NVCC__) && !defined(__NVCOMPILER)) || defined(__clang__)
#define BENCHMARK_BUILTIN_EXPECT(x, y) …
#define BENCHMARK_DEPRECATED_MSG(msg) …
#define BENCHMARK_DISABLE_DEPRECATED_WARNING …
#define BENCHMARK_RESTORE_DEPRECATED_WARNING …
#elif defined(__NVCOMPILER)
#define BENCHMARK_BUILTIN_EXPECT …
#define BENCHMARK_DEPRECATED_MSG …
#define BENCHMARK_DISABLE_DEPRECATED_WARNING …
#define BENCHMARK_RESTORE_DEPRECATED_WARNING …
#else
#define BENCHMARK_BUILTIN_EXPECT …
#define BENCHMARK_DEPRECATED_MSG …
#define BENCHMARK_WARNING_MSG …
#define BENCHMARK_DISABLE_DEPRECATED_WARNING
#define BENCHMARK_RESTORE_DEPRECATED_WARNING
#endif
#if defined(__GNUC__) && !defined(__clang__)
#define BENCHMARK_GCC_VERSION …
#endif
#ifndef __has_builtin
#define __has_builtin …
#endif
#if defined(__GNUC__) || __has_builtin(__builtin_unreachable)
#define BENCHMARK_UNREACHABLE() …
#elif defined(_MSC_VER)
#define BENCHMARK_UNREACHABLE …
#else
#define BENCHMARK_UNREACHABLE …
#endif
#ifdef BENCHMARK_HAS_CXX11
#define BENCHMARK_OVERRIDE …
#else
#define BENCHMARK_OVERRIDE
#endif
#if defined(_MSC_VER)
#pragma warning(push)
#pragma warning(disable : 4251)
#endif
namespace benchmark {
class BenchmarkReporter;
const char kDefaultMinTimeStr[] = …;
BENCHMARK_EXPORT std::string GetBenchmarkVersion();
BENCHMARK_EXPORT void PrintDefaultHelp();
BENCHMARK_EXPORT void Initialize(int* argc, char** argv,
void (*HelperPrinterf)() = PrintDefaultHelp);
BENCHMARK_EXPORT void Shutdown();
BENCHMARK_EXPORT bool ReportUnrecognizedArguments(int argc, char** argv);
BENCHMARK_EXPORT std::string GetBenchmarkFilter();
BENCHMARK_EXPORT void SetBenchmarkFilter(std::string value);
BENCHMARK_EXPORT int32_t GetBenchmarkVerbosity();
BENCHMARK_EXPORT BenchmarkReporter* CreateDefaultDisplayReporter();
BENCHMARK_EXPORT size_t RunSpecifiedBenchmarks();
BENCHMARK_EXPORT size_t RunSpecifiedBenchmarks(std::string spec);
BENCHMARK_EXPORT size_t
RunSpecifiedBenchmarks(BenchmarkReporter* display_reporter);
BENCHMARK_EXPORT size_t
RunSpecifiedBenchmarks(BenchmarkReporter* display_reporter, std::string spec);
BENCHMARK_EXPORT size_t RunSpecifiedBenchmarks(
BenchmarkReporter* display_reporter, BenchmarkReporter* file_reporter);
BENCHMARK_EXPORT size_t
RunSpecifiedBenchmarks(BenchmarkReporter* display_reporter,
BenchmarkReporter* file_reporter, std::string spec);
enum TimeUnit { … };
BENCHMARK_EXPORT TimeUnit GetDefaultTimeUnit();
BENCHMARK_EXPORT void SetDefaultTimeUnit(TimeUnit unit);
class MemoryManager { … };
BENCHMARK_EXPORT
void RegisterMemoryManager(MemoryManager* memory_manager);
BENCHMARK_EXPORT
void AddCustomContext(const std::string& key, const std::string& value);
namespace internal {
class Benchmark;
class BenchmarkImp;
class BenchmarkFamilies;
BENCHMARK_EXPORT std::map<std::string, std::string>*& GetGlobalContext();
BENCHMARK_EXPORT
void UseCharPointer(char const volatile*);
BENCHMARK_EXPORT Benchmark* RegisterBenchmarkInternal(Benchmark*);
BENCHMARK_EXPORT int InitializeStreams();
BENCHMARK_UNUSED static int stream_init_anchor = …;
}
#if (!defined(__GNUC__) && !defined(__clang__)) || defined(__pnacl__) || \
defined(__EMSCRIPTEN__)
#define BENCHMARK_HAS_NO_INLINE_ASSEMBLY
#endif
#ifdef BENCHMARK_HAS_CXX11
inline BENCHMARK_ALWAYS_INLINE void ClobberMemory() { … }
#endif
#ifndef BENCHMARK_HAS_NO_INLINE_ASSEMBLY
#if !defined(__GNUC__) || defined(__llvm__) || defined(__INTEL_COMPILER)
template <class Tp>
BENCHMARK_DEPRECATED_MSG(
"The const-ref version of this method can permit "
"undesired compiler optimizations in benchmarks")
inline BENCHMARK_ALWAYS_INLINE void DoNotOptimize(Tp const& value) { … }
template <class Tp>
inline BENCHMARK_ALWAYS_INLINE void DoNotOptimize(Tp& value) { … }
#ifdef BENCHMARK_HAS_CXX11
template <class Tp>
inline BENCHMARK_ALWAYS_INLINE void DoNotOptimize(Tp&& value) { … }
#endif
#elif defined(BENCHMARK_HAS_CXX11) && (__GNUC__ >= 5)
template <class Tp>
BENCHMARK_DEPRECATED_MSG(
"The const-ref version of this method can permit "
"undesired compiler optimizations in benchmarks")
inline BENCHMARK_ALWAYS_INLINE
typename std::enable_if<std::is_trivially_copyable<Tp>::value &&
(sizeof(Tp) <= sizeof(Tp*))>::type
DoNotOptimize(Tp const& value) {
asm volatile("" : : "r,m"(value) : "memory");
}
template <class Tp>
BENCHMARK_DEPRECATED_MSG(
"The const-ref version of this method can permit "
"undesired compiler optimizations in benchmarks")
inline BENCHMARK_ALWAYS_INLINE
typename std::enable_if<!std::is_trivially_copyable<Tp>::value ||
(sizeof(Tp) > sizeof(Tp*))>::type
DoNotOptimize(Tp const& value) {
asm volatile("" : : "m"(value) : "memory");
}
template <class Tp>
inline BENCHMARK_ALWAYS_INLINE
typename std::enable_if<std::is_trivially_copyable<Tp>::value &&
(sizeof(Tp) <= sizeof(Tp*))>::type
DoNotOptimize(Tp& value) {
asm volatile("" : "+m,r"(value) : : "memory");
}
template <class Tp>
inline BENCHMARK_ALWAYS_INLINE
typename std::enable_if<!std::is_trivially_copyable<Tp>::value ||
(sizeof(Tp) > sizeof(Tp*))>::type
DoNotOptimize(Tp& value) {
asm volatile("" : "+m"(value) : : "memory");
}
template <class Tp>
inline BENCHMARK_ALWAYS_INLINE
typename std::enable_if<std::is_trivially_copyable<Tp>::value &&
(sizeof(Tp) <= sizeof(Tp*))>::type
DoNotOptimize(Tp&& value) {
asm volatile("" : "+m,r"(value) : : "memory");
}
template <class Tp>
inline BENCHMARK_ALWAYS_INLINE
typename std::enable_if<!std::is_trivially_copyable<Tp>::value ||
(sizeof(Tp) > sizeof(Tp*))>::type
DoNotOptimize(Tp&& value) {
asm volatile("" : "+m"(value) : : "memory");
}
#else
template <class Tp>
BENCHMARK_DEPRECATED_MSG(
"The const-ref version of this method can permit "
"undesired compiler optimizations in benchmarks")
inline BENCHMARK_ALWAYS_INLINE void DoNotOptimize(Tp const& value) {
asm volatile("" : : "m"(value) : "memory");
}
template <class Tp>
inline BENCHMARK_ALWAYS_INLINE void DoNotOptimize(Tp& value) {
asm volatile("" : "+m"(value) : : "memory");
}
#ifdef BENCHMARK_HAS_CXX11
template <class Tp>
inline BENCHMARK_ALWAYS_INLINE void DoNotOptimize(Tp&& value) {
asm volatile("" : "+m"(value) : : "memory");
}
#endif
#endif
#ifndef BENCHMARK_HAS_CXX11
inline BENCHMARK_ALWAYS_INLINE void ClobberMemory() {
asm volatile("" : : : "memory");
}
#endif
#elif defined(_MSC_VER)
template <class Tp>
BENCHMARK_DEPRECATED_MSG(
"The const-ref version of this method can permit "
"undesired compiler optimizations in benchmarks")
inline BENCHMARK_ALWAYS_INLINE void DoNotOptimize(Tp const& value) {
internal::UseCharPointer(&reinterpret_cast<char const volatile&>(value));
_ReadWriteBarrier();
}
#ifndef BENCHMARK_HAS_CXX11
inline BENCHMARK_ALWAYS_INLINE void ClobberMemory() { _ReadWriteBarrier(); }
#endif
#else
#ifdef BENCHMARK_HAS_CXX11
template <class Tp>
inline BENCHMARK_ALWAYS_INLINE void DoNotOptimize(Tp&& value) {
internal::UseCharPointer(&reinterpret_cast<char const volatile&>(value));
}
#else
template <class Tp>
BENCHMARK_DEPRECATED_MSG(
"The const-ref version of this method can permit "
"undesired compiler optimizations in benchmarks")
inline BENCHMARK_ALWAYS_INLINE void DoNotOptimize(Tp const& value) {
internal::UseCharPointer(&reinterpret_cast<char const volatile&>(value));
}
template <class Tp>
inline BENCHMARK_ALWAYS_INLINE void DoNotOptimize(Tp& value) {
internal::UseCharPointer(&reinterpret_cast<char const volatile&>(value));
}
#endif
#endif
class Counter { … };
Counter::Flags inline operator|(const Counter::Flags& LHS,
const Counter::Flags& RHS) { … }
UserCounters;
enum BigO { … };
ComplexityN;
IterationCount;
enum StatisticUnit { … };
BigOFunc;
StatisticsFunc;
namespace internal {
struct Statistics { … };
class BenchmarkInstance;
class ThreadTimer;
class ThreadManager;
class PerfCountersMeasurement;
enum AggregationReportMode
#if defined(BENCHMARK_HAS_CXX11)
: unsigned
#else
#endif
{ … };
enum Skipped
#if defined(BENCHMARK_HAS_CXX11)
: unsigned
#endif
{ … };
}
class BENCHMARK_EXPORT State { … };
inline BENCHMARK_ALWAYS_INLINE bool State::KeepRunning() { … }
inline BENCHMARK_ALWAYS_INLINE bool State::KeepRunningBatch(IterationCount n) { … }
inline BENCHMARK_ALWAYS_INLINE bool State::KeepRunningInternal(IterationCount n,
bool is_batch) { … }
struct State::StateIterator { … };
inline BENCHMARK_ALWAYS_INLINE State::StateIterator State::begin() { … }
inline BENCHMARK_ALWAYS_INLINE State::StateIterator State::end() { … }
namespace internal {
Function;
class BENCHMARK_EXPORT Benchmark { … };
}
internal::Benchmark* RegisterBenchmark(const std::string& name,
internal::Function* fn);
#if defined(BENCHMARK_HAS_CXX11)
template <class Lambda>
internal::Benchmark* RegisterBenchmark(const std::string& name, Lambda&& fn);
#endif
BENCHMARK_EXPORT void ClearRegisteredBenchmarks();
namespace internal {
class BENCHMARK_EXPORT FunctionBenchmark : public Benchmark { … };
#ifdef BENCHMARK_HAS_CXX11
template <class Lambda>
class LambdaBenchmark : public Benchmark { … };
#endif
}
inline internal::Benchmark* RegisterBenchmark(const std::string& name,
internal::Function* fn) { … }
#ifdef BENCHMARK_HAS_CXX11
template <class Lambda>
internal::Benchmark* RegisterBenchmark(const std::string& name, Lambda&& fn) { … }
#endif
#if defined(BENCHMARK_HAS_CXX11) && \
(!defined(BENCHMARK_GCC_VERSION) || BENCHMARK_GCC_VERSION >= 409)
template <class Lambda, class... Args>
internal::Benchmark* RegisterBenchmark(const std::string& name, Lambda&& fn,
Args&&... args) { … }
#else
#define BENCHMARK_HAS_NO_VARIADIC_REGISTER_BENCHMARK
#endif
class Fixture : public internal::Benchmark { … };
}
#if defined(__COUNTER__) && (__COUNTER__ + 1 == __COUNTER__ + 0)
#define BENCHMARK_PRIVATE_UNIQUE_ID …
#else
#define BENCHMARK_PRIVATE_UNIQUE_ID …
#endif
#ifdef BENCHMARK_HAS_CXX11
#define BENCHMARK_PRIVATE_NAME(...) …
#else
#define BENCHMARK_PRIVATE_NAME …
#endif
#define BENCHMARK_PRIVATE_CONCAT(a, b, c) …
#define BENCHMARK_PRIVATE_CONCAT2(a, b, c) …
#define BENCHMARK_PRIVATE_CONCAT_NAME(BaseClass, Method) …
#define BENCHMARK_PRIVATE_DECLARE(n) …
#ifdef BENCHMARK_HAS_CXX11
#define BENCHMARK(...) …
#else
#define BENCHMARK …
#endif
#define BENCHMARK_WITH_ARG(n, a) …
#define BENCHMARK_WITH_ARG2(n, a1, a2) …
#define BENCHMARK_WITH_UNIT(n, t) …
#define BENCHMARK_RANGE(n, lo, hi) …
#define BENCHMARK_RANGE2(n, l1, h1, l2, h2) …
#ifdef BENCHMARK_HAS_CXX11
#define BENCHMARK_CAPTURE(func, test_case_name, ...) …
#endif
#define BENCHMARK_TEMPLATE1(n, a) …
#define BENCHMARK_TEMPLATE2(n, a, b) …
#ifdef BENCHMARK_HAS_CXX11
#define BENCHMARK_TEMPLATE(n, ...) …
#else
#define BENCHMARK_TEMPLATE …
#endif
#ifdef BENCHMARK_HAS_CXX11
#define BENCHMARK_TEMPLATE1_CAPTURE(func, a, test_case_name, ...) …
#define BENCHMARK_TEMPLATE2_CAPTURE(func, a, b, test_case_name, ...) …
#endif
#define BENCHMARK_PRIVATE_DECLARE_F(BaseClass, Method) …
#define BENCHMARK_TEMPLATE1_PRIVATE_DECLARE_F(BaseClass, Method, a) …
#define BENCHMARK_TEMPLATE2_PRIVATE_DECLARE_F(BaseClass, Method, a, b) …
#ifdef BENCHMARK_HAS_CXX11
#define BENCHMARK_TEMPLATE_PRIVATE_DECLARE_F(BaseClass, Method, ...) …
#else
#define BENCHMARK_TEMPLATE_PRIVATE_DECLARE_F …
#endif
#define BENCHMARK_DEFINE_F(BaseClass, Method) …
#define BENCHMARK_TEMPLATE1_DEFINE_F(BaseClass, Method, a) …
#define BENCHMARK_TEMPLATE2_DEFINE_F(BaseClass, Method, a, b) …
#ifdef BENCHMARK_HAS_CXX11
#define BENCHMARK_TEMPLATE_DEFINE_F(BaseClass, Method, ...) …
#else
#define BENCHMARK_TEMPLATE_DEFINE_F …
#endif
#define BENCHMARK_REGISTER_F(BaseClass, Method) …
#define BENCHMARK_PRIVATE_REGISTER_F(TestName) …
#define BENCHMARK_F(BaseClass, Method) …
#define BENCHMARK_TEMPLATE1_F(BaseClass, Method, a) …
#define BENCHMARK_TEMPLATE2_F(BaseClass, Method, a, b) …
#ifdef BENCHMARK_HAS_CXX11
#define BENCHMARK_TEMPLATE_F(BaseClass, Method, ...) …
#else
#define BENCHMARK_TEMPLATE_F …
#endif
#define BENCHMARK_MAIN() …
namespace benchmark {
struct BENCHMARK_EXPORT CPUInfo { … };
struct BENCHMARK_EXPORT SystemInfo { … };
struct BENCHMARK_EXPORT BenchmarkName { … };
class BENCHMARK_EXPORT BenchmarkReporter { … };
class BENCHMARK_EXPORT ConsoleReporter : public BenchmarkReporter { … };
class BENCHMARK_EXPORT JSONReporter : public BenchmarkReporter { … };
class BENCHMARK_EXPORT BENCHMARK_DEPRECATED_MSG(
"The CSV Reporter will be removed in a future release") CSVReporter
: public BenchmarkReporter { … };
inline const char* GetTimeUnitString(TimeUnit unit) { … }
inline double GetTimeUnitMultiplier(TimeUnit unit) { … }
BENCHMARK_EXPORT
std::vector<int64_t> CreateRange(int64_t lo, int64_t hi, int multi);
BENCHMARK_EXPORT
std::vector<int64_t> CreateDenseRange(int64_t start, int64_t limit, int step);
}
#if defined(_MSC_VER)
#pragma warning(pop)
#endif
#endif