CppBenchmark  1.0.4.0
C++ Benchmark Library
executor.h
Go to the documentation of this file.
1 
9 #ifndef CPPBENCHMARK_EXECUTOR_H
10 #define CPPBENCHMARK_EXECUTOR_H
11 
12 #include "benchmark/phase_core.h"
13 #include "benchmark/reporter.h"
14 
15 namespace CppBenchmark {
16 
18 
21 class Executor
22 {
23 public:
24  Executor(const Executor&) = delete;
25  Executor(Executor&&) = delete;
26  ~Executor() = default;
27 
28  Executor& operator=(const Executor&) = delete;
29  Executor& operator=(Executor&&) = delete;
30 
32 
40  static std::shared_ptr<Phase> StartBenchmark(const std::string& benchmark);
41 
43 
49  static void StopBenchmark(const std::string& benchmark);
50 
52 
58  static std::shared_ptr<PhaseScope> ScopeBenchmark(const std::string& benchmark)
59  { return std::make_shared<PhaseScope>(StartBenchmark(benchmark)); }
60 
62 
67  static void Report(Reporter& reporter);
68 
69 protected:
71  std::mutex _mutex;
73  std::vector<std::shared_ptr<PhaseCore>> _benchmarks;
74 
75 private:
76  Executor() = default;
77 
78  void ReportPhase(Reporter& reporter, const PhaseCore& phase, const std::string& name) const;
79 
81  static Executor& GetInstance()
82  { static Executor instance; return instance; }
83 };
84 
87 } // namespace CppBenchmark
88 
89 #endif // CPPBENCHMARK_EXECUTOR_H
Dynamic benchmarks executor class.
Definition: executor.h:22
std::mutex _mutex
Synchronization mutex.
Definition: executor.h:71
Executor(const Executor &)=delete
static void StopBenchmark(const std::string &benchmark)
Stop dynamic benchmark with a given name.
Definition: executor.cpp:80
static std::shared_ptr< Phase > StartBenchmark(const std::string &benchmark)
Start a new dynamic benchmark with a given name.
Definition: executor.cpp:47
static void Report(Reporter &reporter)
Report benchmarks results using the given reporter.
Definition: executor.cpp:98
std::vector< std::shared_ptr< PhaseCore > > _benchmarks
Registered benchmarks collection.
Definition: executor.h:73
Executor(Executor &&)=delete
Executor & operator=(const Executor &)=delete
Executor & operator=(Executor &&)=delete
static std::shared_ptr< PhaseScope > ScopeBenchmark(const std::string &benchmark)
Start a new dynamic benchmark with a given name and wrap it in a PhaseScope.
Definition: executor.h:58
Benchmark phase core.
Definition: phase_core.h:27
Reporter base class.
Definition: reporter.h:21
C++ Benchmark project definitions.
Definition: barrier.h:15
Benchmark phase core definition.
Reporter base definition.