Skip to content

Commit 5e8f253

Browse files
committed
feat(bench): add macOS-only FibFlamegraphBenchmark
Exists solely to exercise CodSpeed's flamegraph symbolization on codspeed-macro runners. Gated to macOS via a Gradle excludes rule so the Linux/Windows matrix jobs skip it.
1 parent c66b399 commit 5e8f253

2 files changed

Lines changed: 37 additions & 1 deletion

File tree

examples/example-gradle/build.gradle.kts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import org.gradle.internal.os.OperatingSystem
2+
13
plugins {
24
java
35
id("me.champeau.jmh") version "0.7.2"
@@ -30,9 +32,16 @@ jmh {
3032
// regex passed to JMH, so multiple entries collapse to one pattern with
3133
// literal commas and match nothing. Use a single alternation instead.
3234
includes.set(listOf(
33-
".*(SleepBenchmark|BacktrackingBenchmark|FibBenchmark).*",
35+
".*(SleepBenchmark|BacktrackingBenchmark|FibBenchmark|FibFlamegraphBenchmark).*",
3436
))
3537
}
38+
39+
// FibFlamegraphBenchmark exists only to exercise the macOS flamegraph
40+
// pipeline on codspeed-macro runners. Skip it on Linux/Windows so the
41+
// cross-platform jobs don't run a redundant fib variant.
42+
if (!OperatingSystem.current().isMacOsX) {
43+
excludes.add(".*FibFlamegraphBenchmark.*")
44+
}
3645
}
3746

3847
sourceSets {
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package bench;
2+
3+
import java.util.concurrent.TimeUnit;
4+
import org.openjdk.jmh.annotations.*;
5+
6+
/**
7+
* macOS-only benchmark whose recursion shape produces an easily-recognisable flamegraph. Gated to
8+
* macOS via Gradle excludes in {@code build.gradle.kts}.
9+
*/
10+
@BenchmarkMode(Mode.AverageTime)
11+
@OutputTimeUnit(TimeUnit.NANOSECONDS)
12+
@State(Scope.Benchmark)
13+
public class FibFlamegraphBenchmark {
14+
15+
@Param({"35"})
16+
private int n;
17+
18+
@Benchmark
19+
public long fib() {
20+
return fib(n);
21+
}
22+
23+
private static long fib(int n) {
24+
if (n <= 1) return n;
25+
return fib(n - 1) + fib(n - 2);
26+
}
27+
}

0 commit comments

Comments
 (0)