Update README to mention UseRealTime for wallclock time measurements.

Also adding a use case in the API header.

Fixes #170
This commit is contained in:
Eli Bendersky 2015-12-30 06:01:19 -08:00
parent f662e8be5b
commit c7ab1b987b
2 changed files with 19 additions and 8 deletions

View File

@ -145,9 +145,10 @@ Three macros are provided for adding benchmark templates.
#define BENCHMARK_TEMPLATE2(func, arg1, arg2) #define BENCHMARK_TEMPLATE2(func, arg1, arg2)
``` ```
In a multithreaded test, it is guaranteed that none of the threads will start In a multithreaded test (benchmark invoked by multiple threads simultaneously),
until all have called KeepRunning, and all will have finished before KeepRunning it is guaranteed that none of the threads will start until all have called
returns false. As such, any global setup or teardown you want to do can be KeepRunning, and all will have finished before KeepRunning returns false. As
such, any global setup or teardown you want to do can be
wrapped in a check against the thread index: wrapped in a check against the thread index:
```c++ ```c++
@ -165,6 +166,16 @@ static void BM_MultiThreaded(benchmark::State& state) {
BENCHMARK(BM_MultiThreaded)->Threads(2); BENCHMARK(BM_MultiThreaded)->Threads(2);
``` ```
If the benchmarked code itself uses threads and you want to compare it to
single-threaded code, you may want to use real-time ("wallclock") measurements
for latency comparisons:
```c++
BENCHMARK(BM_test)->Range(8, 8<<10)->UseRealTime();
```
Without `UseRealTime`, CPU time is used by default.
To prevent a value or expression from being optimized away by the compiler To prevent a value or expression from being optimized away by the compiler
the `benchmark::DoNotOptimize(...)` function can be used. the `benchmark::DoNotOptimize(...)` function can be used.

View File

@ -417,11 +417,11 @@ public:
// option overrides the `benchmark_min_time` flag. // option overrides the `benchmark_min_time` flag.
Benchmark* MinTime(double t); Benchmark* MinTime(double t);
// If a particular benchmark is I/O bound, or if for some reason CPU // If a particular benchmark is I/O bound, runs multiple threads internally or
// timings are not representative, call this method. If called, the elapsed // if for some reason CPU timings are not representative, call this method. If
// time will be used to control how many iterations are run, and in the // called, the elapsed time will be used to control how many iterations are
// printing of items/second or MB/seconds values. If not called, the cpu // run, and in the printing of items/second or MB/seconds values. If not
// time used by the benchmark will be used. // called, the cpu time used by the benchmark will be used.
Benchmark* UseRealTime(); Benchmark* UseRealTime();
// Support for running multiple copies of the same benchmark concurrently // Support for running multiple copies of the same benchmark concurrently