Skip to content

Commit 6f15825

Browse files
committed
fix: remove memory allocations, use fixed iteration count
1 parent 1bb4513 commit 6f15825

File tree

2 files changed

+5
-14
lines changed

2 files changed

+5
-14
lines changed

examples/google_benchmark_cmake/helper.hpp

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,8 @@ NOINLINE static uint64_t recursive_fib(int n) {
1919
}
2020

2121
NOINLINE static uint64_t expensive_operation() {
22-
// Large memory allocation
23-
std::vector<uint64_t> data(1024 * 1024, 42); // 8 MiB allocation
24-
25-
// Expensive recursive computation that will dominate flamegraph
26-
uint64_t fib_result = recursive_fib(30);
27-
28-
// More expensive work
29-
uint64_t sum = std::accumulate(data.begin(), data.end(), uint64_t(0));
30-
benchmark::DoNotOptimize(sum);
31-
benchmark::DoNotOptimize(fib_result);
32-
33-
return sum + fib_result;
22+
// Expensive recursive compuation that will dominate flamegraph
23+
return 42 + recursive_fib(30);
3424
}
3525

3626
#endif // HELPER_HPP

examples/google_benchmark_cmake/pause_timing_bench.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ static void BM_large_drop(benchmark::State& state) {
2525
state.ResumeTiming();
2626
}
2727
}
28-
BENCHMARK(BM_large_drop);
28+
// IMPORTANT: Use fixed iterations, otherwise we'll run for 10+ minutes
29+
BENCHMARK(BM_large_drop)->Iterations(100);
2930

3031
static void BM_large_setup(benchmark::State& state) {
3132
for (auto _ : state) {
@@ -36,4 +37,4 @@ static void BM_large_setup(benchmark::State& state) {
3637
benchmark::DoNotOptimize(actual_work());
3738
}
3839
}
39-
BENCHMARK(BM_large_setup);
40+
BENCHMARK(BM_large_setup)->Iterations(100);

0 commit comments

Comments
 (0)