mirror of
https://github.com/google/benchmark.git
synced 2024-12-26 12:30:14 +08:00
Merge pull request #90 from google/userealtime
Enable UseRealTime and fix documentation for SetLabel.
This commit is contained in:
commit
7c6a7e3084
@ -158,10 +158,6 @@ void RunSpecifiedBenchmarks(const BenchmarkReporter* reporter = nullptr);
|
||||
// ------------------------------------------------------
|
||||
// Routines that can be called from within a benchmark
|
||||
|
||||
//
|
||||
// REQUIRES: a benchmark is currently executing
|
||||
void SetLabel(const std::string& label);
|
||||
|
||||
// If this routine is called, peak memory allocation past this point in the
|
||||
// benchmark is reported at the end of the benchmark report line. (It is
|
||||
// computed by running the benchmark once with a single iteration and a memory
|
||||
@ -212,10 +208,10 @@ class State {
|
||||
// If this routine is called, the specified label is printed at the
|
||||
// end of the benchmark report line for the currently executing
|
||||
// benchmark. Example:
|
||||
// static void BM_Compress(int iters) {
|
||||
// static void BM_Compress(benchmark::State& state) {
|
||||
// ...
|
||||
// double compress = input_size / output_size;
|
||||
// benchmark::SetLabel(StringPrintf("compress:%.1f%%", 100.0*compression));
|
||||
// state.SetLabel(StringPrintf("compress:%.1f%%", 100.0*compression));
|
||||
// }
|
||||
// Produces output that looks like:
|
||||
// BM_Compress 50 50 14115038 compress:27.3%
|
||||
|
@ -416,8 +416,6 @@ void MemoryUsage() {
|
||||
}
|
||||
*/
|
||||
|
||||
void UseRealTime() { use_real_time = true; }
|
||||
|
||||
void PrintUsageAndExit() {
|
||||
fprintf(stdout,
|
||||
"benchmark [--benchmark_filter=<regex>]\n"
|
||||
@ -1176,6 +1174,8 @@ void RunSpecifiedBenchmarks(const BenchmarkReporter* reporter /*= nullptr*/) {
|
||||
spec, reporter == nullptr ? &default_reporter : reporter);
|
||||
}
|
||||
|
||||
void UseRealTime() { use_real_time = true; }
|
||||
|
||||
void Initialize(int* argc, const char** argv) {
|
||||
internal::ParseCommandLineFlags(argc, argv);
|
||||
internal::SetLogLevel(FLAGS_v);
|
||||
|
@ -57,6 +57,17 @@ static void BM_Factorial(benchmark::State& state) {
|
||||
}
|
||||
BENCHMARK(BM_Factorial);
|
||||
|
||||
static void BM_FactorialRealTime(benchmark::State& state) {
|
||||
benchmark::UseRealTime();
|
||||
|
||||
int fac_42 = 0;
|
||||
while (state.KeepRunning())
|
||||
fac_42 = Factorial(8);
|
||||
// Prevent compiler optimizations
|
||||
std::cout << fac_42;
|
||||
}
|
||||
BENCHMARK(BM_FactorialRealTime);
|
||||
|
||||
static void BM_CalculatePiRange(benchmark::State& state) {
|
||||
double pi = 0.0;
|
||||
while (state.KeepRunning())
|
||||
|
Loading…
Reference in New Issue
Block a user