diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml new file mode 100644 index 0000000..0695beb --- /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: "StableRNGs" + job-summary: true diff --git a/benchmark/benchmarks.jl b/benchmark/benchmarks.jl new file mode 100644 index 0000000..a3df2a8 --- /dev/null +++ b/benchmark/benchmarks.jl @@ -0,0 +1,22 @@ +using FastPower, BenchmarkTools +using StableRNGs + +const SUITE = BenchmarkGroup() +const rng = StableRNG(123) + +xs = rand(rng, 10_000) + +# ============================================================================= +# fastpower vs ^ +# ============================================================================= + +SUITE["fastpower"] = BenchmarkGroup() + +SUITE["fastpower"]["int_exp"] = @benchmarkable sum(fastpower.($xs, 3)) +SUITE["fastpower"]["int_large"] = @benchmarkable sum(fastpower.($xs, 17)) +SUITE["fastpower"]["float_exp"] = @benchmarkable sum(fastpower.($xs, 2.5)) +SUITE["fastpower"]["neg_exp"] = @benchmarkable sum(fastpower.($xs, -2)) + +SUITE["baseline"] = BenchmarkGroup() +SUITE["baseline"]["pow3"] = @benchmarkable sum($xs .^ 3) +SUITE["baseline"]["pow2_5"] = @benchmarkable sum($xs .^ 2.5)