mirror of https://github.com/google/benchmark.git
Return 0 from State::iterations() when not yet started. (#598)
* Return a reasonable value from State::iterations() even before starting a benchmark * Optimize State::iterations() for started case.
This commit is contained in:
parent
6d74c0625b
commit
ce3fde16cb
|
@ -575,7 +575,10 @@ class State {
|
|||
|
||||
BENCHMARK_ALWAYS_INLINE
|
||||
size_t iterations() const {
|
||||
return (max_iterations - total_iterations_ + batch_leftover_);
|
||||
if (BENCHMARK_BUILTIN_EXPECT(!started_, false)) {
|
||||
return 0;
|
||||
}
|
||||
return max_iterations - total_iterations_ + batch_leftover_;
|
||||
}
|
||||
|
||||
private: // items we expect on the first cache line (ie 64 bytes of the struct)
|
||||
|
|
|
@ -99,6 +99,7 @@ BENCHMARK(BM_empty_stop_start)->ThreadPerCpu();
|
|||
|
||||
void BM_KeepRunning(benchmark::State& state) {
|
||||
size_t iter_count = 0;
|
||||
assert(iter_count == state.iterations());
|
||||
while (state.KeepRunning()) {
|
||||
++iter_count;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue