Skip to content

Commit cfc0abb

Browse files
committed
feat(bench): add Darwin-specific fib variant for macOS flamegraph coverage
1 parent 926cefa commit cfc0abb

2 files changed

Lines changed: 15 additions & 7 deletions

File tree

.github/workflows/ci.yml

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -224,10 +224,8 @@ jobs:
224224
225225
- name: Run the benchmarks
226226
uses: CodSpeedHQ/action@main
227-
env:
228-
CODSPEED_SKIP_UPLOAD: "true"
229227
with:
230-
run: examples/google_benchmark_cmake/build/benchmark_example --benchmark_filter=Fibo
228+
run: examples/google_benchmark_cmake/build/benchmark_example --benchmark_filter=BM_FibonacciRecursive_Darwin
231229
mode: walltime
232230
# TODO: Remove this once the runner has been released with macos support
233231
runner-version: branch:main
@@ -252,14 +250,13 @@ jobs:
252250
253251
- name: Run the benchmarks
254252
uses: CodSpeedHQ/action@main
255-
env:
256-
CODSPEED_SKIP_UPLOAD: "true"
257253
with:
258254
# Note: using bazel run directly fails with a permission error on `/var/tmp/_bazel_codspeed/`
259255
# This is because bazel does not like the user switch between running `bazel build` as a user then running `bazel run` as sudo and refuses to run.
260256
# For now, `$USER` remains the original user, but the program is ran with uid 0 with `sudo --preserve-env`
261257
# This problem is temporary because the runner does not YET do the same uid/gid spoofing on macos as it does on linux.
262-
run: ./bazel-bin/examples/google_benchmark_bazel/my_benchmark --benchmark_filter=Fibo
258+
#
259+
# BUILD_WORKSPACE_DIRECTORY is normally set by `bazel run`; we set it manually so workspace-relative __FILE__ resolution works when invoking the binary directly.
260+
run: BUILD_WORKSPACE_DIRECTORY=$PWD ./bazel-bin/examples/google_benchmark_bazel/my_benchmark --benchmark_filter=BM_FibonacciRecursive_Darwin
263261
mode: walltime
264-
# TODO: Remove this once the runner has been released with macos support
265262
runner-version: branch:main

examples/google_benchmark_cmake/fibonacci_bench.hpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,17 @@ static void BM_FibonacciRecursive(benchmark::State& state) {
1616
}
1717
BENCHMARK(BM_FibonacciRecursive)->Arg(35)->MinTime(5);
1818

19+
#ifdef __APPLE__
20+
static void BM_FibonacciRecursive_Darwin(benchmark::State& state) {
21+
int n = static_cast<int>(state.range(0));
22+
for (auto _ : state) {
23+
uint64_t result = fibonacci_recursive(n);
24+
benchmark::DoNotOptimize(result);
25+
}
26+
}
27+
BENCHMARK(BM_FibonacciRecursive_Darwin)->Arg(35)->MinTime(5);
28+
#endif
29+
1930
static uint64_t fibonacci_iterative(int n) {
2031
if (n <= 1) return n;
2132

0 commit comments

Comments
 (0)