43class BENCHMARK_EXPORT BENCHMARK_INTERNAL_CACHELINE_ALIGNED State {
51 inline bool KeepRunning();
53 inline bool KeepRunningBatch(IterationCount n);
60 inline BENCHMARK_ALWAYS_INLINE
void PauseTiming() {
61 assert(in_timed_section() &&
62 "PauseTiming() called outside of the benchmark loop");
68 inline BENCHMARK_ALWAYS_INLINE
void ResumeTiming() {
69 assert(in_timed_section() &&
70 "ResumeTiming() called outside of the benchmark loop");
74 void SkipWithMessage(
const std::string& msg);
76 void SkipWithError(
const std::string& msg);
78 bool skipped()
const {
return internal::NotSkipped != skipped_; }
80 bool in_timed_section()
const {
return started_ && !finished_ && !skipped(); }
82 bool error_occurred()
const {
return internal::SkippedWithError == skipped_; }
84 void SetIterationTime(
double seconds);
86 BENCHMARK_ALWAYS_INLINE
87 void SetBytesProcessed(int64_t bytes) {
88 counters[
"bytes_per_second"] =
89 Counter(
static_cast<double>(bytes), Counter::kIsRate, Counter::kIs1024);
92 BENCHMARK_ALWAYS_INLINE
93 int64_t bytes_processed()
const {
94 if (counters.find(
"bytes_per_second") != counters.end())
95 return static_cast<int64_t
>(counters.at(
"bytes_per_second"));
99 BENCHMARK_ALWAYS_INLINE
100 void SetComplexityN(ComplexityN complexity_n) {
101 complexity_n_ = complexity_n;
104 BENCHMARK_ALWAYS_INLINE
105 ComplexityN complexity_length_n()
const {
return complexity_n_; }
107 BENCHMARK_ALWAYS_INLINE
108 void SetItemsProcessed(int64_t items) {
109 counters[
"items_per_second"] =
110 Counter(
static_cast<double>(items), benchmark::Counter::kIsRate);
113 BENCHMARK_ALWAYS_INLINE
114 int64_t items_processed()
const {
115 if (counters.find(
"items_per_second") != counters.end())
116 return static_cast<int64_t
>(counters.at(
"items_per_second"));
120 void SetLabel(
const std::string& label);
122 BENCHMARK_ALWAYS_INLINE
123 int64_t range(std::size_t pos = 0)
const {
124 assert(range_.size() > pos);
128 BENCHMARK_DEPRECATED_MSG(
"use 'range(0)' instead")
129 int64_t range_x()
const {
return range(0); }
131 BENCHMARK_DEPRECATED_MSG(
"use 'range(1)' instead")
132 int64_t range_y()
const {
return range(1); }
134 BENCHMARK_ALWAYS_INLINE
135 int threads()
const {
return threads_; }
137 BENCHMARK_ALWAYS_INLINE
138 int thread_index()
const {
return thread_index_; }
140 BENCHMARK_ALWAYS_INLINE
141 IterationCount iterations()
const {
142 if (BENCHMARK_BUILTIN_EXPECT(!started_,
false)) {
145 return max_iterations - total_iterations_ + batch_leftover_;
148 BENCHMARK_ALWAYS_INLINE
149 std::string name()
const {
return name_; }
151 size_t range_size()
const {
return range_.size(); }
154 IterationCount total_iterations_;
156 IterationCount batch_leftover_;
159 const IterationCount max_iterations;
164 internal::Skipped skipped_;
166 std::vector<int64_t> range_;
168 ComplexityN complexity_n_;
171 UserCounters counters;
174 State(std::string name, IterationCount max_iters,
175 const std::vector<int64_t>& ranges,
int thread_i,
int n_threads,
180 void StartKeepRunning();
181 inline bool KeepRunningInternal(IterationCount n,
bool is_batch);
182 void FinishKeepRunning();
187 void PauseTimingImpl();
188 void ResumeTimingImpl();
190 const std::string name_;
191 const int thread_index_;
236 typedef std::forward_iterator_tag iterator_category;
237 typedef Value value_type;
238 typedef Value reference;
239 typedef Value pointer;
240 typedef std::ptrdiff_t difference_type;
244 BENCHMARK_ALWAYS_INLINE
245 StateIterator() : cached_(0), parent_() {}
247 BENCHMARK_ALWAYS_INLINE
249 : cached_(st->skipped() ? 0 : st->max_iterations), parent_(st) {}
252 BENCHMARK_ALWAYS_INLINE
253 Value operator*()
const {
return Value(); }
255 BENCHMARK_ALWAYS_INLINE
256 StateIterator& operator++() {
262 BENCHMARK_ALWAYS_INLINE
263 bool operator!=(StateIterator
const&)
const {
264 if (BENCHMARK_BUILTIN_EXPECT(cached_ != 0,
true))
return true;
265 parent_->FinishKeepRunning();
270 IterationCount cached_;
271 State*
const parent_;