Improve README's basic usage example (#433)

This commit is contained in:
Disconnect3d 2017-09-14 09:31:35 +02:00 committed by Dominic Hamon
parent 24b8042733
commit 2a05f248be

View File

@ -18,6 +18,8 @@ IRC channel: https://freenode.net #googlebenchmark
Define a function that executes the code to be measured. Define a function that executes the code to be measured.
```c++ ```c++
#include <benchmark/benchmark.h>
static void BM_StringCreation(benchmark::State& state) { static void BM_StringCreation(benchmark::State& state) {
while (state.KeepRunning()) while (state.KeepRunning())
std::string empty_string; std::string empty_string;
@ -36,6 +38,8 @@ BENCHMARK(BM_StringCopy);
BENCHMARK_MAIN(); BENCHMARK_MAIN();
``` ```
Don't forget to inform your linker to add benchmark library e.g. through `-lbenchmark` compilation flag.
### Passing arguments ### Passing arguments
Sometimes a family of benchmarks can be implemented with just one routine that Sometimes a family of benchmarks can be implemented with just one routine that
takes an extra argument to specify which one of the family of benchmarks to takes an extra argument to specify which one of the family of benchmarks to