diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml new file mode 100644 index 0000000..87afbc1 --- /dev/null +++ b/.github/workflows/benchmark.yml @@ -0,0 +1,29 @@ +name: Benchmark this PR + +on: + pull_request: + branches: [main] + paths-ignore: ['docs/**'] + +permissions: + pull-requests: write + contents: read + +jobs: + benchmark: + runs-on: ubuntu-latest + timeout-minutes: 30 + strategy: + fail-fast: false + matrix: + version: ["1", "lts"] + env: + # Force consistent Julia depot path for self-hosted runners + JULIA_DEPOT_PATH: ~/.julia + steps: + - uses: MilesCranmer/AirspeedVelocity.jl@action-v1 + with: + julia-version: ${{ matrix.version }} + script: "benchmark/benchmarks.jl" + extra-pkgs: "" + job-summary: true diff --git a/benchmark/benchmarks.jl b/benchmark/benchmarks.jl new file mode 100644 index 0000000..dfcc771 --- /dev/null +++ b/benchmark/benchmarks.jl @@ -0,0 +1,34 @@ +using FunctionProperties, BenchmarkTools + +const SUITE = BenchmarkGroup() + +# Representative functions with sample inputs +f_branching(x) = x > 0 ? x : -x +f_linear(x) = 2.0 * x +f_quad(x) = x^2 + 3.0x +f_smooth(x) = sin(x) +f_time(u, p, t) = p .* u .+ t +f_auto(u, p) = p .* u + +x = 1.5 +u = [1.0, 2.0] +p = [0.5, 0.5] + +# ============================================================================= +# Property queries (reflection-based analysis) +# ============================================================================= + +SUITE["queries"] = BenchmarkGroup() + +SUITE["queries"]["hasbranching_true"] = @benchmarkable hasbranching($f_branching, $x) +SUITE["queries"]["hasbranching_false"] = @benchmarkable hasbranching($f_linear, $x) +SUITE["queries"]["islinear"] = @benchmarkable islinear($f_linear, $x) +SUITE["queries"]["isquadratic"] = @benchmarkable isquadratic($f_quad, $x) +SUITE["queries"]["issmooth"] = @benchmarkable issmooth($f_smooth, $x) +SUITE["queries"]["isautonomous_true"] = @benchmarkable isautonomous( + $f_auto, $u, $p +) +SUITE["queries"]["isautonomous_false"] = @benchmarkable isautonomous( + $f_time, $u, $p, 0.5 +) +SUITE["queries"]["is_leaf"] = @benchmarkable is_leaf($f_linear)