From 3b094c169f0fe1b799114fde35f73f2a064a63d4 Mon Sep 17 00:00:00 2001 From: Josh Gao Date: Thu, 26 Oct 2017 13:57:40 -0700 Subject: [PATCH] libbacktrace: let the benchmark library decide iteration count. Manually doing 1000 iterations of the benchmark doesn't seem to add any significant amount of precision, and it makes the benchmark take forever and obfuscates the results. Just let benchmark figure out the time (with the option of using command line flags to increase the number of iterations). Test: backtrace_benchmarks64 Change-Id: I8de912c1b3c904755c8e2ac4175ff70176544ba3 --- libbacktrace/backtrace_benchmarks.cpp | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/libbacktrace/backtrace_benchmarks.cpp b/libbacktrace/backtrace_benchmarks.cpp index aa1662fb1..9fdf60c66 100644 --- a/libbacktrace/backtrace_benchmarks.cpp +++ b/libbacktrace/backtrace_benchmarks.cpp @@ -38,7 +38,6 @@ #define ANDROID_PR_SET_VMA_ANON_NAME 0 constexpr size_t kNumMaps = 2000; -constexpr size_t kNumIterations = 1000; static bool CountMaps(pid_t pid, size_t* num_maps) { // Minimize the calls that might allocate memory. If too much memory @@ -132,14 +131,12 @@ static void CreateMap(benchmark::State& state, BacktraceMap* (*map_func)(pid_t, } while (state.KeepRunning()) { - for (size_t i = 0; i < static_cast(state.range(0)); i++) { - BacktraceMap* map = map_func(pid, false); - if (map == nullptr) { - fprintf(stderr, "Failed to create map\n"); - return; - } - delete map; + BacktraceMap* map = map_func(pid, false); + if (map == nullptr) { + fprintf(stderr, "Failed to create map\n"); + return; } + delete map; } kill(pid, SIGKILL); @@ -149,11 +146,11 @@ static void CreateMap(benchmark::State& state, BacktraceMap* (*map_func)(pid_t, static void BM_create_map(benchmark::State& state) { CreateMap(state, BacktraceMap::Create); } -BENCHMARK(BM_create_map)->Arg(kNumIterations); +BENCHMARK(BM_create_map); static void BM_create_map_new(benchmark::State& state) { CreateMap(state, BacktraceMap::CreateNew); } -BENCHMARK(BM_create_map_new)->Arg(kNumIterations); +BENCHMARK(BM_create_map_new); BENCHMARK_MAIN();