163#ifndef BENCHMARK_BENCHMARK_H_
164#define BENCHMARK_BENCHMARK_H_
167#if __cplusplus >= 201103L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201103L)
168#define BENCHMARK_HAS_CXX11
172#if __cplusplus >= 201703L || \
173 (defined(_MSC_VER) && _MSC_VER >= 1911 && _MSVC_LANG >= 201703L)
174#define BENCHMARK_HAS_CXX17
190#if defined(BENCHMARK_HAS_CXX11)
192#include <initializer_list>
193#include <type_traits>
201#ifndef BENCHMARK_HAS_CXX11
202#define BENCHMARK_DISALLOW_COPY_AND_ASSIGN(TypeName) \
203 TypeName(const TypeName&); \
204 TypeName& operator=(const TypeName&)
206#define BENCHMARK_DISALLOW_COPY_AND_ASSIGN(TypeName) \
207 TypeName(const TypeName&) = delete; \
208 TypeName& operator=(const TypeName&) = delete
211#ifdef BENCHMARK_HAS_CXX17
212#define BENCHMARK_UNUSED [[maybe_unused]]
213#elif defined(__GNUC__) || defined(__clang__)
214#define BENCHMARK_UNUSED __attribute__((unused))
216#define BENCHMARK_UNUSED
219#if defined(__GNUC__) || defined(__clang__)
220#define BENCHMARK_ALWAYS_INLINE __attribute__((always_inline))
221#define BENCHMARK_NOEXCEPT noexcept
222#define BENCHMARK_NOEXCEPT_OP(x) noexcept(x)
223#elif defined(_MSC_VER) && !defined(__clang__)
224#define BENCHMARK_ALWAYS_INLINE __forceinline
226#define BENCHMARK_NOEXCEPT noexcept
227#define BENCHMARK_NOEXCEPT_OP(x) noexcept(x)
229#define BENCHMARK_NOEXCEPT
230#define BENCHMARK_NOEXCEPT_OP(x)
232#define __func__ __FUNCTION__
234#define BENCHMARK_ALWAYS_INLINE
235#define BENCHMARK_NOEXCEPT
236#define BENCHMARK_NOEXCEPT_OP(x)
239#define BENCHMARK_INTERNAL_TOSTRING2(x) #x
240#define BENCHMARK_INTERNAL_TOSTRING(x) BENCHMARK_INTERNAL_TOSTRING2(x)
243#if defined(__GNUC__) || defined(__clang__)
244#define BENCHMARK_BUILTIN_EXPECT(x, y) __builtin_expect(x, y)
245#define BENCHMARK_DEPRECATED_MSG(msg) __attribute__((deprecated(msg)))
246#define BENCHMARK_DISABLE_DEPRECATED_WARNING \
247 _Pragma("GCC diagnostic push") \
248 _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
249#define BENCHMARK_RESTORE_DEPRECATED_WARNING _Pragma("GCC diagnostic pop")
251#define BENCHMARK_BUILTIN_EXPECT(x, y) x
252#define BENCHMARK_DEPRECATED_MSG(msg)
253#define BENCHMARK_WARNING_MSG(msg) \
254 __pragma(message(__FILE__ "(" BENCHMARK_INTERNAL_TOSTRING( \
255 __LINE__) ") : warning note: " msg))
256#define BENCHMARK_DISABLE_DEPRECATED_WARNING
257#define BENCHMARK_RESTORE_DEPRECATED_WARNING
261#if defined(__GNUC__) && !defined(__clang__)
262#define BENCHMARK_GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__)
266#define __has_builtin(x) 0
269#if defined(__GNUC__) || __has_builtin(__builtin_unreachable)
270#define BENCHMARK_UNREACHABLE() __builtin_unreachable()
271#elif defined(_MSC_VER)
272#define BENCHMARK_UNREACHABLE() __assume(false)
274#define BENCHMARK_UNREACHABLE() ((void)0)
277#ifdef BENCHMARK_HAS_CXX11
278#define BENCHMARK_OVERRIDE override
280#define BENCHMARK_OVERRIDE
284class BenchmarkReporter;
286void Initialize(
int* argc,
char** argv);
291bool ReportUnrecognizedArguments(
int argc,
char** argv);
294std::string GetBenchmarkFilter();
312size_t RunSpecifiedBenchmarks();
313size_t RunSpecifiedBenchmarks(std::string spec);
315size_t RunSpecifiedBenchmarks(BenchmarkReporter* display_reporter);
316size_t RunSpecifiedBenchmarks(BenchmarkReporter* display_reporter,
319size_t RunSpecifiedBenchmarks(BenchmarkReporter* display_reporter,
320 BenchmarkReporter* file_reporter);
321size_t RunSpecifiedBenchmarks(BenchmarkReporter* display_reporter,
322 BenchmarkReporter* file_reporter,
330 static const int64_t TombstoneValue;
336 total_allocated_bytes(TombstoneValue),
337 net_heap_growth(TombstoneValue) {}
343 int64_t max_bytes_used;
347 int64_t total_allocated_bytes;
352 int64_t net_heap_growth;
358 virtual void Start() = 0;
361 BENCHMARK_DEPRECATED_MSG(
"Use Stop(Result&) instead")
362 virtual
void Stop(Result* result) = 0;
365 BENCHMARK_DISABLE_DEPRECATED_WARNING
366 virtual
void Stop(Result& result) { Stop(&result); }
367 BENCHMARK_RESTORE_DEPRECATED_WARNING
372void RegisterMemoryManager(MemoryManager* memory_manager);
375void AddCustomContext(
const std::string& key,
const std::string& value);
380class BenchmarkFamilies;
382void UseCharPointer(
char const volatile*);
386Benchmark* RegisterBenchmarkInternal(Benchmark*);
389int InitializeStreams();
390BENCHMARK_UNUSED
static int stream_init_anchor = InitializeStreams();
394#if (!defined(__GNUC__) && !defined(__clang__)) || defined(__pnacl__) || \
395 defined(__EMSCRIPTEN__)
396#define BENCHMARK_HAS_NO_INLINE_ASSEMBLY
401#ifdef BENCHMARK_HAS_CXX11
402inline BENCHMARK_ALWAYS_INLINE
void ClobberMemory() {
403 std::atomic_signal_fence(std::memory_order_acq_rel);
411#ifndef BENCHMARK_HAS_NO_INLINE_ASSEMBLY
413inline BENCHMARK_ALWAYS_INLINE
void DoNotOptimize(Tp
const& value) {
414 asm volatile(
"" : :
"r,m"(value) :
"memory");
418inline BENCHMARK_ALWAYS_INLINE
void DoNotOptimize(Tp& value) {
419#if defined(__clang__)
420 asm volatile(
"" :
"+r,m"(value) : :
"memory");
422 asm volatile(
"" :
"+m,r"(value) : :
"memory");
426#ifndef BENCHMARK_HAS_CXX11
427inline BENCHMARK_ALWAYS_INLINE
void ClobberMemory() {
428 asm volatile(
"" : : :
"memory");
431#elif defined(_MSC_VER)
433inline BENCHMARK_ALWAYS_INLINE
void DoNotOptimize(Tp
const& value) {
434 internal::UseCharPointer(&
reinterpret_cast<char const volatile&
>(value));
438#ifndef BENCHMARK_HAS_CXX11
439inline BENCHMARK_ALWAYS_INLINE
void ClobberMemory() { _ReadWriteBarrier(); }
443inline BENCHMARK_ALWAYS_INLINE
void DoNotOptimize(Tp
const& value) {
444 internal::UseCharPointer(&
reinterpret_cast<char const volatile&
>(value));
459 kAvgThreads = 1 << 1,
461 kAvgThreadsRate = kIsRate | kAvgThreads,
464 kIsIterationInvariant = 1 << 2,
468 kIsIterationInvariantRate = kIsRate | kIsIterationInvariant,
471 kAvgIterations = 1 << 3,
473 kAvgIterationsRate = kIsRate | kAvgIterations,
490 BENCHMARK_ALWAYS_INLINE
491 Counter(
double v = 0., Flags f = kDefaults, OneK k = kIs1000)
492 : value(v), flags(f), oneK(k) {}
494 BENCHMARK_ALWAYS_INLINE
operator double const &()
const {
return value; }
495 BENCHMARK_ALWAYS_INLINE
operator double&() {
return value; }
500Counter::Flags
inline operator|(
const Counter::Flags& LHS,
501 const Counter::Flags& RHS) {
502 return static_cast<Counter::Flags
>(
static_cast<int>(LHS) |
503 static_cast<int>(RHS));
507typedef std::map<std::string, Counter> UserCounters;
511enum TimeUnit { kNanosecond, kMicrosecond, kMillisecond, kSecond };
517enum BigO { oNone, o1, oN, oNSquared, oNCubed, oLogN, oNLogN, oAuto, oLambda };
519typedef uint64_t IterationCount;
521enum StatisticUnit { kTime, kPercentage };
525typedef double(BigOFunc)(IterationCount);
529typedef double(StatisticsFunc)(
const std::vector<double>&);
534 StatisticsFunc* compute_;
537 Statistics(
const std::string& name, StatisticsFunc* compute,
538 StatisticUnit unit = kTime)
539 : name_(name), compute_(compute), unit_(unit) {}
547enum AggregationReportMode
548#if defined(BENCHMARK_HAS_CXX11)
557 ARM_Default = 1U << 0U,
559 ARM_FileReportAggregatesOnly = 1U << 1U,
561 ARM_DisplayReportAggregatesOnly = 1U << 2U,
563 ARM_ReportAggregatesOnly =
564 ARM_FileReportAggregatesOnly | ARM_DisplayReportAggregatesOnly
601 bool KeepRunningBatch(IterationCount n);
649 void SkipWithError(
const char* msg);
652 bool error_occurred()
const {
return error_occurred_; }
661 void SetIterationTime(
double seconds);
668 BENCHMARK_ALWAYS_INLINE
669 void SetBytesProcessed(int64_t bytes) {
670 counters[
"bytes_per_second"] =
671 Counter(
static_cast<double>(bytes), Counter::kIsRate, Counter::kIs1024);
674 BENCHMARK_ALWAYS_INLINE
675 int64_t bytes_processed()
const {
676 if (counters.find(
"bytes_per_second") != counters.end())
677 return static_cast<int64_t
>(counters.at(
"bytes_per_second"));
686 BENCHMARK_ALWAYS_INLINE
687 void SetComplexityN(int64_t complexity_n) { complexity_n_ = complexity_n; }
689 BENCHMARK_ALWAYS_INLINE
690 int64_t complexity_length_n()
const {
return complexity_n_; }
698 BENCHMARK_ALWAYS_INLINE
699 void SetItemsProcessed(int64_t items) {
700 counters[
"items_per_second"] =
701 Counter(
static_cast<double>(items), benchmark::Counter::kIsRate);
704 BENCHMARK_ALWAYS_INLINE
705 int64_t items_processed()
const {
706 if (counters.find(
"items_per_second") != counters.end())
707 return static_cast<int64_t
>(counters.at(
"items_per_second"));
723 void SetLabel(
const char* label);
725 void BENCHMARK_ALWAYS_INLINE SetLabel(
const std::string& str) {
726 this->SetLabel(str.c_str());
730 BENCHMARK_ALWAYS_INLINE
731 int64_t range(std::size_t pos = 0)
const {
732 assert(range_.size() > pos);
736 BENCHMARK_DEPRECATED_MSG(
"use 'range(0)' instead")
737 int64_t range_x()
const {
return range(0); }
739 BENCHMARK_DEPRECATED_MSG(
"use 'range(1)' instead")
740 int64_t range_y()
const {
return range(1); }
743 BENCHMARK_ALWAYS_INLINE
744 int threads()
const {
return threads_; }
747 BENCHMARK_ALWAYS_INLINE
748 int thread_index()
const {
return thread_index_; }
750 BENCHMARK_ALWAYS_INLINE
751 IterationCount iterations()
const {
752 if (BENCHMARK_BUILTIN_EXPECT(!started_,
false)) {
755 return max_iterations - total_iterations_ + batch_leftover_;
762 IterationCount total_iterations_;
767 IterationCount batch_leftover_;
770 const IterationCount max_iterations;
775 bool error_occurred_;
778 std::vector<int64_t> range_;
780 int64_t complexity_n_;
784 UserCounters counters;
787 State(IterationCount max_iters,
const std::vector<int64_t>& ranges,
792 void StartKeepRunning();
795 bool KeepRunningInternal(IterationCount n,
bool is_batch);
796 void FinishKeepRunning();
798 const int thread_index_;
808inline BENCHMARK_ALWAYS_INLINE
bool State::KeepRunning() {
809 return KeepRunningInternal(1,
false);
812inline BENCHMARK_ALWAYS_INLINE
bool State::KeepRunningBatch(IterationCount n) {
813 return KeepRunningInternal(n,
true);
816inline BENCHMARK_ALWAYS_INLINE
bool State::KeepRunningInternal(IterationCount n,
822 assert(is_batch || n == 1);
823 if (BENCHMARK_BUILTIN_EXPECT(total_iterations_ >= n,
true)) {
824 total_iterations_ -= n;
829 if (!error_occurred_ && total_iterations_ >= n) {
830 total_iterations_ -= n;
835 if (is_batch && total_iterations_ != 0) {
836 batch_leftover_ = n - total_iterations_;
837 total_iterations_ = 0;
846 typedef std::forward_iterator_tag iterator_category;
850 typedef std::ptrdiff_t difference_type;
854 BENCHMARK_ALWAYS_INLINE
857 BENCHMARK_ALWAYS_INLINE
859 : cached_(st->error_occurred_ ? 0 : st->max_iterations), parent_(st) {}
862 BENCHMARK_ALWAYS_INLINE
863 Value operator*()
const {
return Value(); }
865 BENCHMARK_ALWAYS_INLINE
866 StateIterator& operator++() {
872 BENCHMARK_ALWAYS_INLINE
873 bool operator!=(StateIterator
const&)
const {
874 if (BENCHMARK_BUILTIN_EXPECT(cached_ != 0,
true))
return true;
875 parent_->FinishKeepRunning();
880 IterationCount cached_;
881 State*
const parent_;
884inline BENCHMARK_ALWAYS_INLINE State::StateIterator State::begin() {
885 return StateIterator(
this);
887inline BENCHMARK_ALWAYS_INLINE State::StateIterator State::end() {
889 return StateIterator();
894typedef void(Function)(State&);
910 Benchmark* Name(
const std::string& name);
923 Benchmark* Range(int64_t start, int64_t limit);
928 Benchmark* DenseRange(int64_t start, int64_t limit,
int step = 1);
933 Benchmark* Args(
const std::vector<int64_t>& args);
938 Benchmark* ArgPair(int64_t x, int64_t y) {
939 std::vector<int64_t> args;
948 Benchmark* Ranges(
const std::vector<std::pair<int64_t, int64_t> >& ranges);
953 Benchmark* ArgsProduct(
const std::vector<std::vector<int64_t> >& arglists);
956 Benchmark* ArgName(
const std::string& name);
960 Benchmark* ArgNames(
const std::vector<std::string>& names);
965 Benchmark* RangePair(int64_t lo1, int64_t hi1, int64_t lo2, int64_t hi2) {
966 std::vector<std::pair<int64_t, int64_t> > ranges;
967 ranges.push_back(std::make_pair(lo1, hi1));
968 ranges.push_back(std::make_pair(lo2, hi2));
969 return Ranges(ranges);
996 Benchmark* RangeMultiplier(
int multiplier);
1009 Benchmark* Iterations(IterationCount n);
1020 Benchmark* ReportAggregatesOnly(
bool value =
true);
1023 Benchmark* DisplayAggregatesOnly(
bool value =
true);
1050 Benchmark* Complexity(BigO complexity = benchmark::oAuto);
1054 Benchmark* Complexity(BigOFunc* complexity);
1057 Benchmark* ComputeStatistics(
const std::string& name,
1058 StatisticsFunc* statistics,
1059 StatisticUnit unit = kTime);
1080 Benchmark* ThreadRange(
int min_threads,
int max_threads);
1086 Benchmark* DenseThreadRange(
int min_threads,
int max_threads,
int stride = 1);
1091 virtual void Run(
State& state) = 0;
1096 void SetName(
const char* name);
1098 int ArgsCnt()
const;
1105 AggregationReportMode aggregation_report_mode_;
1106 std::vector<std::string> arg_names_;
1107 std::vector<std::vector<int64_t> > args_;
1108 TimeUnit time_unit_;
1109 int range_multiplier_;
1111 IterationCount iterations_;
1113 bool measure_process_cpu_time_;
1114 bool use_real_time_;
1115 bool use_manual_time_;
1117 BigOFunc* complexity_lambda_;
1118 std::vector<Statistics> statistics_;
1119 std::vector<int> thread_counts_;
1122 callback_function setup_;
1123 callback_function teardown_;
1135 internal::Function* fn);
1137#if defined(BENCHMARK_HAS_CXX11)
1138template <
class Lambda>
1144void ClearRegisteredBenchmarks();
1154 virtual void Run(
State& st) BENCHMARK_OVERRIDE;
1160#ifdef BENCHMARK_HAS_CXX11
1161template <
class Lambda>
1162class LambdaBenchmark :
public Benchmark {
1164 virtual void Run(
State& st) BENCHMARK_OVERRIDE { lambda_(st); }
1167 template <
class OLambda>
1168 LambdaBenchmark(
const char* name, OLambda&& lam)
1169 : Benchmark(name), lambda_(std::forward<OLambda>(lam)) {}
1171 LambdaBenchmark(LambdaBenchmark
const&) =
delete;
1173 template <
class Lam>
1174 friend Benchmark* ::benchmark::RegisterBenchmark(
const char*, Lam&&);
1182inline internal::Benchmark* RegisterBenchmark(
const char* name,
1183 internal::Function* fn) {
1184 return internal::RegisterBenchmarkInternal(
1185 ::new internal::FunctionBenchmark(name, fn));
1188#ifdef BENCHMARK_HAS_CXX11
1189template <
class Lambda>
1190internal::Benchmark* RegisterBenchmark(
const char* name, Lambda&& fn) {
1192 internal::LambdaBenchmark<typename std::decay<Lambda>::type>;
1193 return internal::RegisterBenchmarkInternal(
1194 ::new BenchType(name, std::forward<Lambda>(fn)));
1198#if defined(BENCHMARK_HAS_CXX11) && \
1199 (!defined(BENCHMARK_GCC_VERSION) || BENCHMARK_GCC_VERSION >= 409)
1200template <
class Lambda,
class... Args>
1201internal::Benchmark* RegisterBenchmark(
const char* name, Lambda&& fn,
1203 return benchmark::RegisterBenchmark(
1207#define BENCHMARK_HAS_NO_VARIADIC_REGISTER_BENCHMARK
1215 virtual void Run(
State& st) BENCHMARK_OVERRIDE {
1217 this->BenchmarkCase(st);
1222 virtual void SetUp(
const State&) {}
1223 virtual void TearDown(
const State&) {}
1225 virtual void SetUp(
State& st) { SetUp(
const_cast<const State&
>(st)); }
1226 virtual void TearDown(
State& st) { TearDown(
const_cast<const State&
>(st)); }
1229 virtual void BenchmarkCase(
State&) = 0;
1240#if defined(__COUNTER__) && (__COUNTER__ + 1 == __COUNTER__ + 0)
1241#define BENCHMARK_PRIVATE_UNIQUE_ID __COUNTER__
1243#define BENCHMARK_PRIVATE_UNIQUE_ID __LINE__
1247#ifdef BENCHMARK_HAS_CXX11
1248#define BENCHMARK_PRIVATE_NAME(...) \
1249 BENCHMARK_PRIVATE_CONCAT(benchmark_uniq_, BENCHMARK_PRIVATE_UNIQUE_ID, \
1252#define BENCHMARK_PRIVATE_NAME(n) \
1253 BENCHMARK_PRIVATE_CONCAT(benchmark_uniq_, BENCHMARK_PRIVATE_UNIQUE_ID, n)
1256#define BENCHMARK_PRIVATE_CONCAT(a, b, c) BENCHMARK_PRIVATE_CONCAT2(a, b, c)
1257#define BENCHMARK_PRIVATE_CONCAT2(a, b, c) a##b##c
1259#define BENCHMARK_PRIVATE_CONCAT_NAME(BaseClass, Method) \
1260 BaseClass##_##Method##_Benchmark
1262#define BENCHMARK_PRIVATE_DECLARE(n) \
1263 static ::benchmark::internal::Benchmark* BENCHMARK_PRIVATE_NAME(n) \
1266#ifdef BENCHMARK_HAS_CXX11
1267#define BENCHMARK(...) \
1268 BENCHMARK_PRIVATE_DECLARE(_benchmark_) = \
1269 (::benchmark::internal::RegisterBenchmarkInternal( \
1270 new ::benchmark::internal::FunctionBenchmark(#__VA_ARGS__, \
1273#define BENCHMARK(n) \
1274 BENCHMARK_PRIVATE_DECLARE(n) = \
1275 (::benchmark::internal::RegisterBenchmarkInternal( \
1276 new ::benchmark::internal::FunctionBenchmark(#n, n)))
1280#define BENCHMARK_WITH_ARG(n, a) BENCHMARK(n)->Arg((a))
1281#define BENCHMARK_WITH_ARG2(n, a1, a2) BENCHMARK(n)->Args({(a1), (a2)})
1282#define BENCHMARK_WITH_UNIT(n, t) BENCHMARK(n)->Unit((t))
1283#define BENCHMARK_RANGE(n, lo, hi) BENCHMARK(n)->Range((lo), (hi))
1284#define BENCHMARK_RANGE2(n, l1, h1, l2, h2) \
1285 BENCHMARK(n)->RangePair({{(l1), (h1)}, {(l2), (h2)}})
1287#ifdef BENCHMARK_HAS_CXX11
1300#define BENCHMARK_CAPTURE(func, test_case_name, ...) \
1301 BENCHMARK_PRIVATE_DECLARE(func) = \
1302 (::benchmark::internal::RegisterBenchmarkInternal( \
1303 new ::benchmark::internal::FunctionBenchmark( \
1304 #func "/" #test_case_name, \
1305 [](::benchmark::State& st) { func(st, __VA_ARGS__); })))
1317#define BENCHMARK_TEMPLATE1(n, a) \
1318 BENCHMARK_PRIVATE_DECLARE(n) = \
1319 (::benchmark::internal::RegisterBenchmarkInternal( \
1320 new ::benchmark::internal::FunctionBenchmark(#n "<" #a ">", n<a>)))
1322#define BENCHMARK_TEMPLATE2(n, a, b) \
1323 BENCHMARK_PRIVATE_DECLARE(n) = \
1324 (::benchmark::internal::RegisterBenchmarkInternal( \
1325 new ::benchmark::internal::FunctionBenchmark(#n "<" #a "," #b ">", \
1328#ifdef BENCHMARK_HAS_CXX11
1329#define BENCHMARK_TEMPLATE(n, ...) \
1330 BENCHMARK_PRIVATE_DECLARE(n) = \
1331 (::benchmark::internal::RegisterBenchmarkInternal( \
1332 new ::benchmark::internal::FunctionBenchmark( \
1333 #n "<" #__VA_ARGS__ ">", n<__VA_ARGS__>)))
1335#define BENCHMARK_TEMPLATE(n, a) BENCHMARK_TEMPLATE1(n, a)
1338#define BENCHMARK_PRIVATE_DECLARE_F(BaseClass, Method) \
1339 class BaseClass##_##Method##_Benchmark : public BaseClass { \
1341 BaseClass##_##Method##_Benchmark() { \
1342 this->SetName(#BaseClass "/" #Method); \
1346 virtual void BenchmarkCase(::benchmark::State&) BENCHMARK_OVERRIDE; \
1349#define BENCHMARK_TEMPLATE1_PRIVATE_DECLARE_F(BaseClass, Method, a) \
1350 class BaseClass##_##Method##_Benchmark : public BaseClass<a> { \
1352 BaseClass##_##Method##_Benchmark() { \
1353 this->SetName(#BaseClass "<" #a ">/" #Method); \
1357 virtual void BenchmarkCase(::benchmark::State&) BENCHMARK_OVERRIDE; \
1360#define BENCHMARK_TEMPLATE2_PRIVATE_DECLARE_F(BaseClass, Method, a, b) \
1361 class BaseClass##_##Method##_Benchmark : public BaseClass<a, b> { \
1363 BaseClass##_##Method##_Benchmark() { \
1364 this->SetName(#BaseClass "<" #a "," #b ">/" #Method); \
1368 virtual void BenchmarkCase(::benchmark::State&) BENCHMARK_OVERRIDE; \
1371#ifdef BENCHMARK_HAS_CXX11
1372#define BENCHMARK_TEMPLATE_PRIVATE_DECLARE_F(BaseClass, Method, ...) \
1373 class BaseClass##_##Method##_Benchmark : public BaseClass<__VA_ARGS__> { \
1375 BaseClass##_##Method##_Benchmark() { \
1376 this->SetName(#BaseClass "<" #__VA_ARGS__ ">/" #Method); \
1380 virtual void BenchmarkCase(::benchmark::State&) BENCHMARK_OVERRIDE; \
1383#define BENCHMARK_TEMPLATE_PRIVATE_DECLARE_F(n, a) \
1384 BENCHMARK_TEMPLATE1_PRIVATE_DECLARE_F(n, a)
1387#define BENCHMARK_DEFINE_F(BaseClass, Method) \
1388 BENCHMARK_PRIVATE_DECLARE_F(BaseClass, Method) \
1389 void BENCHMARK_PRIVATE_CONCAT_NAME(BaseClass, Method)::BenchmarkCase
1391#define BENCHMARK_TEMPLATE1_DEFINE_F(BaseClass, Method, a) \
1392 BENCHMARK_TEMPLATE1_PRIVATE_DECLARE_F(BaseClass, Method, a) \
1393 void BENCHMARK_PRIVATE_CONCAT_NAME(BaseClass, Method)::BenchmarkCase
1395#define BENCHMARK_TEMPLATE2_DEFINE_F(BaseClass, Method, a, b) \
1396 BENCHMARK_TEMPLATE2_PRIVATE_DECLARE_F(BaseClass, Method, a, b) \
1397 void BENCHMARK_PRIVATE_CONCAT_NAME(BaseClass, Method)::BenchmarkCase
1399#ifdef BENCHMARK_HAS_CXX11
1400#define BENCHMARK_TEMPLATE_DEFINE_F(BaseClass, Method, ...) \
1401 BENCHMARK_TEMPLATE_PRIVATE_DECLARE_F(BaseClass, Method, __VA_ARGS__) \
1402 void BENCHMARK_PRIVATE_CONCAT_NAME(BaseClass, Method)::BenchmarkCase
1404#define BENCHMARK_TEMPLATE_DEFINE_F(BaseClass, Method, a) \
1405 BENCHMARK_TEMPLATE1_DEFINE_F(BaseClass, Method, a)
1408#define BENCHMARK_REGISTER_F(BaseClass, Method) \
1409 BENCHMARK_PRIVATE_REGISTER_F(BENCHMARK_PRIVATE_CONCAT_NAME(BaseClass, Method))
1411#define BENCHMARK_PRIVATE_REGISTER_F(TestName) \
1412 BENCHMARK_PRIVATE_DECLARE(TestName) = \
1413 (::benchmark::internal::RegisterBenchmarkInternal(new TestName()))
1416#define BENCHMARK_F(BaseClass, Method) \
1417 BENCHMARK_PRIVATE_DECLARE_F(BaseClass, Method) \
1418 BENCHMARK_REGISTER_F(BaseClass, Method); \
1419 void BENCHMARK_PRIVATE_CONCAT_NAME(BaseClass, Method)::BenchmarkCase
1421#define BENCHMARK_TEMPLATE1_F(BaseClass, Method, a) \
1422 BENCHMARK_TEMPLATE1_PRIVATE_DECLARE_F(BaseClass, Method, a) \
1423 BENCHMARK_REGISTER_F(BaseClass, Method); \
1424 void BENCHMARK_PRIVATE_CONCAT_NAME(BaseClass, Method)::BenchmarkCase
1426#define BENCHMARK_TEMPLATE2_F(BaseClass, Method, a, b) \
1427 BENCHMARK_TEMPLATE2_PRIVATE_DECLARE_F(BaseClass, Method, a, b) \
1428 BENCHMARK_REGISTER_F(BaseClass, Method); \
1429 void BENCHMARK_PRIVATE_CONCAT_NAME(BaseClass, Method)::BenchmarkCase
1431#ifdef BENCHMARK_HAS_CXX11
1432#define BENCHMARK_TEMPLATE_F(BaseClass, Method, ...) \
1433 BENCHMARK_TEMPLATE_PRIVATE_DECLARE_F(BaseClass, Method, __VA_ARGS__) \
1434 BENCHMARK_REGISTER_F(BaseClass, Method); \
1435 void BENCHMARK_PRIVATE_CONCAT_NAME(BaseClass, Method)::BenchmarkCase
1437#define BENCHMARK_TEMPLATE_F(BaseClass, Method, a) \
1438 BENCHMARK_TEMPLATE1_F(BaseClass, Method, a)
1442#define BENCHMARK_MAIN() \
1443 int main(int argc, char** argv) { \
1444 ::benchmark::Initialize(&argc, argv); \
1445 if (::benchmark::ReportUnrecognizedArguments(argc, argv)) return 1; \
1446 ::benchmark::RunSpecifiedBenchmarks(); \
1447 ::benchmark::Shutdown(); \
1450 int main(int, char**)
1455namespace benchmark {
1465 enum Scaling { UNKNOWN, ENABLED, DISABLED };
1469 double cycles_per_second;
1470 std::vector<CacheInfo> caches;
1471 std::vector<double> load_avg;
1477 BENCHMARK_DISALLOW_COPY_AND_ASSIGN(
CPUInfo);
1487 BENCHMARK_DISALLOW_COPY_AND_ASSIGN(
SystemInfo);
1494 std::string function_name;
1496 std::string min_time;
1497 std::string iterations;
1498 std::string repetitions;
1499 std::string time_type;
1500 std::string threads;
1504 std::string str()
const;
1518 size_t name_field_width;
1519 static const char* executable_name;
1524 static const int64_t no_repetition_index = -1;
1525 enum RunType { RT_Iteration, RT_Aggregate };
1528 : run_type(RT_Iteration),
1529 aggregate_unit(kTime),
1530 error_occurred(
false),
1533 time_unit(kNanosecond),
1534 real_accumulated_time(0),
1535 cpu_accumulated_time(0),
1536 max_heapbytes_used(0),
1538 complexity_lambda(),
1540 report_big_o(
false),
1542 memory_result(NULL),
1543 allocs_per_iter(0.0) {}
1545 std::string benchmark_name()
const;
1547 int64_t family_index;
1548 int64_t per_family_instance_index;
1550 std::string aggregate_name;
1551 StatisticUnit aggregate_unit;
1552 std::string report_label;
1553 bool error_occurred;
1554 std::string error_message;
1556 IterationCount iterations;
1558 int64_t repetition_index;
1559 int64_t repetitions;
1561 double real_accumulated_time;
1562 double cpu_accumulated_time;
1568 double GetAdjustedRealTime()
const;
1574 double GetAdjustedCPUTime()
const;
1577 double max_heapbytes_used;
1581 BigOFunc* complexity_lambda;
1582 int64_t complexity_n;
1585 const std::vector<internal::Statistics>* statistics;
1591 UserCounters counters;
1595 double allocs_per_iter;
1608 std::vector<BenchmarkReporter::Run> Runs;
1621 virtual bool ReportContext(
const Context& context) = 0;
1630 virtual void ReportRuns(
const std::vector<Run>& report) = 0;
1634 virtual void Finalize() {}
1638 void SetOutputStream(std::ostream* out) {
1640 output_stream_ = out;
1645 void SetErrorStream(std::ostream* err) {
1647 error_stream_ = err;
1650 std::ostream& GetOutputStream()
const {
return *output_stream_; }
1652 std::ostream& GetErrorStream()
const {
return *error_stream_; }
1654 virtual ~BenchmarkReporter();
1659 static void PrintBasicContext(std::ostream* out, Context
const& context);
1662 std::ostream* output_stream_;
1663 std::ostream* error_stream_;
1670 enum OutputOptions {
1674 OO_ColorTabular = OO_Color | OO_Tabular,
1675 OO_Defaults = OO_ColorTabular
1678 : output_options_(opts_), name_field_width_(0), printed_header_(
false) {}
1680 virtual bool ReportContext(
const Context& context) BENCHMARK_OVERRIDE;
1681 virtual void ReportRuns(
const std::vector<Run>& reports) BENCHMARK_OVERRIDE;
1684 virtual void PrintRunData(
const Run& report);
1685 virtual void PrintHeader(
const Run& report);
1687 OutputOptions output_options_;
1688 size_t name_field_width_;
1689 UserCounters prev_counters_;
1690 bool printed_header_;
1696 virtual bool ReportContext(
const Context& context) BENCHMARK_OVERRIDE;
1697 virtual void ReportRuns(
const std::vector<Run>& reports) BENCHMARK_OVERRIDE;
1698 virtual void Finalize() BENCHMARK_OVERRIDE;
1701 void PrintRunData(
const Run& report);
1706class BENCHMARK_DEPRECATED_MSG(
1707 "The CSV Reporter will be removed in a future release") CSVReporter
1710 CSVReporter() : printed_header_(false) {}
1711 virtual bool ReportContext(
const Context& context) BENCHMARK_OVERRIDE;
1712 virtual void ReportRuns(
const std::vector<Run>& reports) BENCHMARK_OVERRIDE;
1715 void PrintRunData(
const Run& report);
1717 bool printed_header_;
1718 std::set<std::string> user_counter_names_;
1721inline const char* GetTimeUnitString(TimeUnit unit) {
1732 BENCHMARK_UNREACHABLE();
1735inline double GetTimeUnitMultiplier(TimeUnit unit) {
1746 BENCHMARK_UNREACHABLE();
1758std::vector<int64_t> CreateRange(int64_t lo, int64_t hi,
int multi);
1761std::vector<int64_t> CreateDenseRange(int64_t start, int64_t limit,
int step);
Definition: benchmark.h:1512
Definition: benchmark.h:1668
Definition: benchmark.h:450
Definition: benchmark.h:1211
Definition: benchmark.h:1693
Definition: benchmark.h:328
Definition: benchmark.h:571
Definition: benchmark_register.cc:70
Definition: benchmark_api_internal.h:18
Definition: benchmark.h:902
Definition: benchmark.h:1149
Definition: perf_counters.h:125
Definition: thread_manager.h:12
Definition: thread_timer.h:10
Definition: benchmark.h:1493
Definition: benchmark.h:1514
Definition: benchmark.h:1598
Definition: benchmark.h:1523
Definition: benchmark.h:1458
Definition: benchmark.h:1457
Definition: benchmark.h:332
Definition: benchmark.h:845
Definition: benchmark.h:844
Definition: benchmark.h:1481
Definition: benchmark.h:532