mirror of
https://github.com/google/benchmark.git
synced 2025-04-29 22:40:33 +08:00
README.md: document State::{Pause,Resume}Timing()
As pointed out in IRC, these are not documented.
This commit is contained in:
parent
0ed529a7e3
commit
57bf879d49
20
README.md
20
README.md
@ -428,6 +428,26 @@ BENCHMARK(BM_test)->Range(8, 8<<10)->UseRealTime();
|
||||
|
||||
Without `UseRealTime`, CPU time is used by default.
|
||||
|
||||
## Controlling timers
|
||||
Normally, the entire duration of the work loop (`for (auto _ : state) {}`)
|
||||
is measured. But sometimes, it is nessesary to do some work inside of
|
||||
that loop, every iteration, but without counting that time to the benchmark time.
|
||||
That is possible, althought it is not recommended, since it has high overhead.
|
||||
|
||||
```c++
|
||||
static void BM_SetInsert_With_Timer_Control(benchmark::State& state) {
|
||||
std::set<int> data;
|
||||
for (auto _ : state) {
|
||||
state.PauseTiming(); // Stop timers. They will not count until they are resumed.
|
||||
data = ConstructRandomSet(state.range(0)); // Do something that should not be measured
|
||||
state.ResumeTiming(); // And resume timers. They are now counting again.
|
||||
// The rest will be measured.
|
||||
for (int j = 0; j < state.range(1); ++j)
|
||||
data.insert(RandomNumber());
|
||||
}
|
||||
}
|
||||
BENCHMARK(BM_SetInsert_With_Timer_Control)->Ranges({{1<<10, 8<<10}, {128, 512}});
|
||||
```
|
||||
|
||||
## Manual timing
|
||||
For benchmarking something for which neither CPU time nor real-time are
|
||||
|
Loading…
Reference in New Issue
Block a user