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..d37efde --- /dev/null +++ b/benchmark/benchmarks.jl @@ -0,0 +1,53 @@ +using FunctionWrappersWrappers, BenchmarkTools + +const SUITE = BenchmarkGroup() + +# FunctionWrappersWrapper wraps one function across multiple argument signatures +argtypes = (Tuple{Float64, Float64}, Tuple{Int, Int}) +rettypes = (Float64, Int) + +# ============================================================================= +# Construction +# ============================================================================= + +SUITE["construct"] = BenchmarkGroup() + +SUITE["construct"]["default"] = @benchmarkable FunctionWrappersWrapper( + +, $argtypes, $rettypes +) +SUITE["construct"]["dictcache"] = @benchmarkable FunctionWrappersWrapper( + +, $argtypes, $rettypes; cache = DictCache() +) +SUITE["construct"]["no_policy"] = @benchmarkable FunctionWrappersWrapper( + +, $argtypes, $rettypes; policy = AllowAll() +) + +# ============================================================================= +# Calls and metadata +# ============================================================================= + +SUITE["call"] = BenchmarkGroup() + +fww = FunctionWrappersWrapper(+, argtypes, rettypes) +fww_dict = FunctionWrappersWrapper(+, argtypes, rettypes; cache = DictCache()) + +SUITE["call"]["float_args"] = @benchmarkable $fww(1.0, 2.0) +SUITE["call"]["int_args"] = @benchmarkable $fww(1, 2) +SUITE["call"]["dictcache"] = @benchmarkable $fww_dict(1.0, 2.0) + +SUITE["call"]["unwrap"] = @benchmarkable unwrap($fww) +SUITE["call"]["wrapped_signatures"] = @benchmarkable wrapped_signatures($fww) +SUITE["call"]["wrapped_return_types"] = @benchmarkable wrapped_return_types($fww) + +# ============================================================================= +# Vector of wrappers +# ============================================================================= + +SUITE["vector"] = BenchmarkGroup() + +fww1 = FunctionWrappersWrapper(sin, (Tuple{Float64},), (Float64,)) +FWW1 = typeof(fww1) +fww_vec = FWW1[sin, tan, log] + +SUITE["vector"]["getindex_call"] = @benchmarkable $fww_vec[1](0.5) +SUITE["vector"]["construct"] = @benchmarkable $FWW1[sin, tan, log]