CppBenchmark  1.0.4.0
C++ Benchmark Library
settings.h
Go to the documentation of this file.
1 
9 #ifndef CPPBENCHMARK_SETTINGS_H
10 #define CPPBENCHMARK_SETTINGS_H
11 
12 #include <cstdint>
13 #include <functional>
14 #include <tuple>
15 #include <vector>
16 
17 namespace CppBenchmark {
18 
20 
31 class Settings
32 {
33  friend class Benchmark;
34  friend class BenchmarkPC;
35  friend class BenchmarkThreads;
36 
37 public:
39  Settings();
41 
44  Settings(int64_t operations);
45  Settings(const Settings&) = default;
46  Settings(Settings&&) noexcept = default;
47  ~Settings() = default;
48 
49  Settings& operator=(const Settings&) = default;
50  Settings& operator=(Settings&&) noexcept = default;
51 
53  int attempts() const noexcept { return _attempts; }
55  bool infinite() const noexcept { return _infinite; }
57  int64_t duration() const noexcept { return _duration; }
59  int64_t operations() const noexcept { return _operations; }
61  const std::vector<int>& threads() const noexcept { return _threads; }
63  const std::vector<std::tuple<int, int>>& pc() const noexcept { return _pc; }
65  const std::vector<std::tuple<int, int, int>>& params() const noexcept { return _params; }
67  const std::tuple<int64_t, int64_t, int>& latency() const noexcept { return _latency_params; }
69  bool latency_auto() const noexcept { return _latency_auto; }
70 
72 
79 
81 
84  Settings& Infinite();
86 
90  Settings& Duration(int64_t duration);
92 
96  Settings& Operations(int64_t operations);
97 
99 
103  Settings& Threads(int threads);
105 
112  Settings& ThreadsRange(int from, int to);
114 
124  Settings& ThreadsRange(int from, int to, const std::function<int (int, int, int&)>& selector);
125 
127 
132  Settings& PC(int producers, int consumers);
134 
144  Settings& PCRange(int producers_from, int producers_to, int consumers_from, int consumers_to);
146 
160  Settings& PCRange(int producers_from, int producers_to, const std::function<int (int, int, int&)>& producers_selector,
161  int consumers_from, int consumers_to, const std::function<int (int, int, int&)>& consumers_selector);
162 
164 
168  Settings& Param(int value);
170 
177  Settings& ParamRange(int from, int to);
179 
189  Settings& ParamRange(int from, int to, const std::function<int (int, int, int&)>& selector);
190 
192 
197  Settings& Pair(int value1, int value2);
199 
209  Settings& PairRange(int from1, int to1, int from2, int to2);
211 
224  Settings& PairRange(int from1, int to1, const std::function<int (int, int, int&)>& selector1,
225  int from2, int to2, const std::function<int (int, int, int&)>& selector2);
226 
228 
234  Settings& Triple(int value1, int value2, int value3);
236 
248  Settings& TripleRange(int from1, int to1, int from2, int to2, int from3, int to3);
250 
267  Settings& TripleRange(int from1, int to1, const std::function<int (int, int, int&)>& selector1,
268  int from2, int to2, const std::function<int (int, int, int&)>& selector2,
269  int from3, int to3, const std::function<int (int, int, int&)>& selector3);
270 
272 
279  Settings& Latency(int64_t lowest, int64_t highest, int significant, bool automatic = true);
280 
281 private:
282  int _attempts;
283  bool _infinite;
284  int64_t _duration;
285  int64_t _operations;
286  std::vector<int> _threads;
287  std::vector<std::tuple<int, int>> _pc;
288  std::vector<std::tuple<int, int, int>> _params;
289  std::tuple<int64_t, int64_t, int> _latency_params;
290  bool _latency_auto;
291 };
292 
293 } // namespace CppBenchmark
294 
295 #endif // CPPBENCHMARK_SETTINGS_H
Benchmark class.
Definition: benchmark.h:22
Producers/Consumers benchmark base class.
Definition: benchmark_pc.h:26
Threads benchmark base class.
Benchmark settings.
Definition: settings.h:32
const std::vector< std::tuple< int, int, int > > & params() const noexcept
Get collection of independent parameters in a benchmark plan.
Definition: settings.h:65
Settings & ParamRange(int from, int to)
Add new single parameter range to the benchmark running plan.
Definition: settings.cpp:166
Settings & Attempts(int attempts)
Set independent benchmark attempts.
Definition: settings.cpp:30
Settings & ThreadsRange(int from, int to)
Add new threads range to the benchmark running plan.
Definition: settings.cpp:67
Settings & Threads(int threads)
Add new threads count to the benchmark running plan.
Definition: settings.cpp:60
Settings & Triple(int value1, int value2, int value3)
Add new parameters triple to the benchmark running plan.
Definition: settings.cpp:258
Settings & PC(int producers, int consumers)
Add new producers/consumers count to the benchmark running plan.
Definition: settings.cpp:101
int attempts() const noexcept
Get count of independent benchmark attempts.
Definition: settings.h:53
Settings & Infinite()
Set infinite benchmark operations flag.
Definition: settings.cpp:36
int64_t duration() const noexcept
Get benchmark duration in milliseconds.
Definition: settings.h:57
bool infinite() const noexcept
Is benchmark running with infinite count of operations (until cancel)?
Definition: settings.h:55
Settings & Operations(int64_t operations)
Set count of operations.
Definition: settings.cpp:44
Settings & PairRange(int from1, int to1, int from2, int to2)
Add new parameters pairs range to the benchmark running plan.
Definition: settings.cpp:207
Settings(const Settings &)=default
const std::tuple< int64_t, int64_t, int > & latency() const noexcept
Get latency parameters.
Definition: settings.h:67
Settings & Latency(int64_t lowest, int64_t highest, int significant, bool automatic=true)
Set latency histogram parameters.
Definition: settings.cpp:333
Settings & TripleRange(int from1, int to1, int from2, int to2, int from3, int to3)
Add new parameters triple range to the benchmark running plan.
Definition: settings.cpp:265
int64_t operations() const noexcept
Get count of operations.
Definition: settings.h:59
Settings & PCRange(int producers_from, int producers_to, int consumers_from, int consumers_to)
Add new producers/consumers range to the benchmark running plan.
Definition: settings.cpp:108
Settings(Settings &&) noexcept=default
const std::vector< std::tuple< int, int > > & pc() const noexcept
Get collection of independent producers/consumers counts in a benchmark plan.
Definition: settings.h:63
Settings & Duration(int64_t duration)
Set benchmark duration in seconds.
Definition: settings.cpp:52
Settings & Pair(int value1, int value2)
Add new parameters pair to the benchmark running plan.
Definition: settings.cpp:200
Settings()
Initialize settings with the default benchmark duration (5 seconds)
Definition: settings.cpp:13
Settings & Param(int value)
Add new single parameter to the benchmark running plan.
Definition: settings.cpp:159
bool latency_auto() const noexcept
Get automatic latency update flag.
Definition: settings.h:69
const std::vector< int > & threads() const noexcept
Get collection of independent threads counts in a benchmark plan.
Definition: settings.h:61
C++ Benchmark project definitions.
Definition: barrier.h:15