Skip to content

Benchmarks

Benchmarks for the AD-safe machinery, reading the analytic gamma-CDF hooks against the bare Distributions.jl functions and timing the per-backend gradients of each hook.

Quick start

Install the benchpkg CLI once:

bash
task benchmark-install
# Or: julia -e 'using Pkg; Pkg.add("AirspeedVelocity")'

then run the suite:

bash
# Benchmark current state
task benchmark

# Compare main branch vs current state
task benchmark-compare

# Filter to specific benchmarks
task benchmark -- --filter=Hooks
task benchmark-compare -- --filter="AD gradients"

Benchmark structure

Baseline/
  Gamma/               (cdf, logcdf, ccdf, logccdf, pdf)

Hooks/
  Gamma/               (cdf_ad_safe, logcdf_ad_safe, ccdf_ad_safe,
                        logccdf_ad_safe, pdf_ad_safe — analytic path)
  Normal (fall-through)/ (cdf_ad_safe, logcdf_ad_safe, pdf_ad_safe —
                        generic method, collapses to Distributions)
  _gamma_cdf/          (scalar, broadcast)

AD gradients/
  <every test/ADFixtures scenario>/
    ForwardDiff, ReverseDiff (tape), Enzyme forward, Enzyme reverse,
    Mooncake forward, Mooncake reverse

Primal cost and gradient cost

The Baseline group times the stock Distributions.jl functions each hook wraps. On a Gamma the hooks route through the analytic gamma-CDF path (_gamma_cdf) rather than SpecialFunctions.gamma_inc, so the gap between Hooks/Gamma and Baseline/Gamma is the cost of the AD-safe detour on a plain (non-AD) call. On a Normal the generic method falls straight through to Distributions, so Hooks/Normal (fall-through) should sit on top of the baseline with no measurable overhead.

The AD gradients group is the point of the package: it times DifferentiationInterface.gradient for every scenario in test/ADFixtures across the ForwardDiff, ReverseDiff, Enzyme, and Mooncake backends, which is where the analytic derivative rules earn their keep.

CI integration

Pull requests benchmark head and base in separate jobs via the benchmark workflow and post a single comparison comment. Pushes to main and tagged releases append to the performance history below.

Performance history

The summary tracks each benchmark suite's headline timing across recent revisions.

Benchmark summary (overall)

SuiteMedian ratioTrendStatus
AD gradients0.16ok
Baseline0.24ok
Hooks0.28ok
time_to_load1.99⚠ reg

Ratio: latest vs oldest shown revision (1.00 = no change, higher = slower/larger). ⚠ reg = at/above the regression threshold.

<details> <summary>Per-suite detail</summary>

Ratio summary

Most recent 3 revisions, columns labelled by commit date.

AD gradients

Time

Benchmarkv0.1.08400c41028f79b...v0.1.0 / 8400c41028f79b...
_gamma_cdf direct/Enzyme forward7.57 ± 0.078 μs7.52 ± 0.065 μs1.01 ± 0.014
_gamma_cdf direct/Enzyme reverse0.308 ± 0.018 μs0.303 ± 0.018 μs1.01 ± 0.084
_gamma_cdf direct/ForwardDiff0.749 ± 0.097 μs0.744 ± 0.097 μs1.01 ± 0.19
_gamma_cdf direct/Mooncake forward6.12 ± 0.79 μs6.03 ± 0.75 μs1.01 ± 0.18
_gamma_cdf direct/Mooncake reverse5.05 ± 0.37 μs5.02 ± 0.38 μs1.01 ± 0.11
_gamma_cdf direct/ReverseDiff (tape)0.862 ± 0.19 μs0.868 ± 0.19 μs0.993 ± 0.31
ccdf_ad_safe Gamma/Enzyme forward9.53 ± 0.09 μs9.48 ± 0.089 μs1.01 ± 0.013
ccdf_ad_safe Gamma/Enzyme reverse4.41 ± 0.063 μs4.4 ± 0.06 μs1 ± 0.02
ccdf_ad_safe Gamma/ForwardDiff1.51 ± 0.013 μs1.52 ± 0.014 μs0.995 ± 0.013
ccdf_ad_safe Gamma/Mooncake forward7.67 ± 0.14 μs7.67 ± 0.14 μs1 ± 0.026
ccdf_ad_safe Gamma/Mooncake reverse21.7 ± 8.6 μs21.7 ± 9 μs0.997 ± 0.57
ccdf_ad_safe Gamma/ReverseDiff (tape)6.51 ± 0.19 μs6.53 ± 0.19 μs0.996 ± 0.042
cdf_ad_safe Gamma/Enzyme forward9.53 ± 0.09 μs9.52 ± 0.1 μs1 ± 0.014
cdf_ad_safe Gamma/Enzyme reverse4.38 ± 0.067 μs4.4 ± 0.067 μs0.995 ± 0.022
cdf_ad_safe Gamma/ForwardDiff1.52 ± 0.013 μs1.51 ± 0.012 μs1.01 ± 0.012
cdf_ad_safe Gamma/Mooncake forward7.77 ± 0.16 μs7.74 ± 0.15 μs1 ± 0.028
cdf_ad_safe Gamma/Mooncake reverse22.1 ± 9 μs22 ± 8.9 μs1.01 ± 0.58
cdf_ad_safe Gamma/ReverseDiff (tape)4.7 ± 0.089 μs4.63 ± 0.086 μs1.01 ± 0.027
logccdf_ad_safe Gamma/Enzyme forward9.59 ± 0.08 μs9.55 ± 0.09 μs1 ± 0.013
logccdf_ad_safe Gamma/Enzyme reverse4.55 ± 0.066 μs4.54 ± 0.076 μs1 ± 0.022
logccdf_ad_safe Gamma/ForwardDiff1.53 ± 0.014 μs1.54 ± 0.012 μs0.994 ± 0.012
logccdf_ad_safe Gamma/Mooncake forward8.04 ± 0.17 μs8.06 ± 0.17 μs0.998 ± 0.029
logccdf_ad_safe Gamma/Mooncake reverse22.3 ± 9 μs22.2 ± 9.1 μs1 ± 0.58
logccdf_ad_safe Gamma/ReverseDiff (tape)5.39 ± 0.86 μs5.35 ± 0.89 μs1.01 ± 0.23
logcdf_ad_safe Gamma/Enzyme forward9.54 ± 0.09 μs9.57 ± 0.091 μs0.997 ± 0.013
logcdf_ad_safe Gamma/Enzyme reverse4.52 ± 0.064 μs4.57 ± 0.057 μs0.989 ± 0.019
logcdf_ad_safe Gamma/ForwardDiff1.53 ± 0.013 μs1.56 ± 0.011 μs0.978 ± 0.011
logcdf_ad_safe Gamma/Mooncake forward7.94 ± 0.15 μs7.92 ± 0.14 μs1 ± 0.026
logcdf_ad_safe Gamma/Mooncake reverse22 ± 9 μs22.2 ± 9.2 μs0.991 ± 0.58
logcdf_ad_safe Gamma/ReverseDiff (tape)5.11 ± 0.36 μs5.07 ± 0.82 μs1.01 ± 0.18
pdf_ad_safe Gamma/Enzyme forward8.37 ± 0.073 μs8.46 ± 0.074 μs0.989 ± 0.012
pdf_ad_safe Gamma/Enzyme reverse3.41 ± 0.055 μs3.42 ± 0.055 μs0.997 ± 0.023
pdf_ad_safe Gamma/ForwardDiff0.837 ± 0.09 μs0.849 ± 0.09 μs0.986 ± 0.15
pdf_ad_safe Gamma/Mooncake forward6.19 ± 0.38 μs6.22 ± 0.31 μs0.994 ± 0.079
pdf_ad_safe Gamma/Mooncake reverse27.9 ± 11 μs27.9 ± 11 μs1 ± 0.57
pdf_ad_safe Gamma/ReverseDiff (tape)15.4 ± 0.42 μs15.2 ± 0.38 μs1.01 ± 0.038

Memory

Benchmarkv0.1.08400c41028f79b...v0.1.0 / 8400c41028f79b...
_gamma_cdf direct/Enzyme forward30 allocs: 1.06 kB30 allocs: 1.06 kB1
_gamma_cdf direct/Enzyme reverse2 allocs: 0.0781 kB2 allocs: 0.0781 kB1
_gamma_cdf direct/ForwardDiff7 allocs: 0.359 kB7 allocs: 0.359 kB1
_gamma_cdf direct/Mooncake forward0.064 k allocs: 3.06 kB0.064 k allocs: 3.06 kB1
_gamma_cdf direct/Mooncake reverse0.064 k allocs: 2.9 kB0.064 k allocs: 2.9 kB1
_gamma_cdf direct/ReverseDiff (tape)16 allocs: 0.656 kB16 allocs: 0.656 kB1
ccdf_ad_safe Gamma/Enzyme forward0.036 k allocs: 1.11 kB0.036 k allocs: 1.11 kB1
ccdf_ad_safe Gamma/Enzyme reverse24 allocs: 1 kB24 allocs: 1 kB1
ccdf_ad_safe Gamma/ForwardDiff7 allocs: 0.266 kB7 allocs: 0.266 kB1
ccdf_ad_safe Gamma/Mooncake forward0.058 k allocs: 2.91 kB0.058 k allocs: 2.91 kB1
ccdf_ad_safe Gamma/Mooncake reverse0.217 k allocs: 26 kB0.217 k allocs: 26 kB1
ccdf_ad_safe Gamma/ReverseDiff (tape)0.082 k allocs: 3.55 kB0.082 k allocs: 3.55 kB1
cdf_ad_safe Gamma/Enzyme forward0.036 k allocs: 1.11 kB0.036 k allocs: 1.11 kB1
cdf_ad_safe Gamma/Enzyme reverse24 allocs: 1 kB24 allocs: 1 kB1
cdf_ad_safe Gamma/ForwardDiff7 allocs: 0.266 kB7 allocs: 0.266 kB1
cdf_ad_safe Gamma/Mooncake forward0.058 k allocs: 2.91 kB0.058 k allocs: 2.91 kB1
cdf_ad_safe Gamma/Mooncake reverse0.217 k allocs: 26 kB0.217 k allocs: 26 kB1
cdf_ad_safe Gamma/ReverseDiff (tape)0.061 k allocs: 2.47 kB0.061 k allocs: 2.47 kB1
logccdf_ad_safe Gamma/Enzyme forward0.036 k allocs: 1.11 kB0.036 k allocs: 1.11 kB1
logccdf_ad_safe Gamma/Enzyme reverse24 allocs: 1.03 kB24 allocs: 1.03 kB1
logccdf_ad_safe Gamma/ForwardDiff7 allocs: 0.266 kB7 allocs: 0.266 kB1
logccdf_ad_safe Gamma/Mooncake forward0.058 k allocs: 2.91 kB0.058 k allocs: 2.91 kB1
logccdf_ad_safe Gamma/Mooncake reverse0.218 k allocs: 26.2 kB0.218 k allocs: 26.2 kB1
logccdf_ad_safe Gamma/ReverseDiff (tape)0.093 k allocs: 3.75 kB0.093 k allocs: 3.75 kB1
logcdf_ad_safe Gamma/Enzyme forward0.036 k allocs: 1.11 kB0.036 k allocs: 1.11 kB1
logcdf_ad_safe Gamma/Enzyme reverse24 allocs: 1.03 kB24 allocs: 1.03 kB1
logcdf_ad_safe Gamma/ForwardDiff7 allocs: 0.266 kB7 allocs: 0.266 kB1
logcdf_ad_safe Gamma/Mooncake forward0.058 k allocs: 2.91 kB0.058 k allocs: 2.91 kB1
logcdf_ad_safe Gamma/Mooncake reverse0.218 k allocs: 26.2 kB0.218 k allocs: 26.2 kB1
logcdf_ad_safe Gamma/ReverseDiff (tape)0.078 k allocs: 3.28 kB0.078 k allocs: 3.28 kB1
pdf_ad_safe Gamma/Enzyme forward0.036 k allocs: 1.11 kB0.036 k allocs: 1.11 kB1
pdf_ad_safe Gamma/Enzyme reverse24 allocs: 1.03 kB24 allocs: 1.03 kB1
pdf_ad_safe Gamma/ForwardDiff7 allocs: 0.266 kB7 allocs: 0.266 kB1
pdf_ad_safe Gamma/Mooncake forward0.058 k allocs: 2.91 kB0.058 k allocs: 2.91 kB1
pdf_ad_safe Gamma/Mooncake reverse0.283 k allocs: 0.0323 MB0.283 k allocs: 0.0323 MB1
pdf_ad_safe Gamma/ReverseDiff (tape)0.243 k allocs: 10.4 kB0.243 k allocs: 10.4 kB1

Baseline

Time

Benchmarkv0.1.08400c41028f79b...v0.1.0 / 8400c41028f79b...
Gamma/ccdf3.59 ± 0.37 μs3.57 ± 0.38 μs1 ± 0.15
Gamma/cdf3.6 ± 0.37 μs3.57 ± 0.38 μs1.01 ± 0.15
Gamma/logccdf5.68 ± 0.065 μs5.66 ± 0.035 μs1 ± 0.013
Gamma/logcdf5.52 ± 0.065 μs5.56 ± 0.044 μs0.993 ± 0.014
Gamma/pdf4.15 ± 0.21 μs4.18 ± 0.2 μs0.991 ± 0.068

Memory

Benchmarkv0.1.08400c41028f79b...v0.1.0 / 8400c41028f79b...
Gamma/ccdf2 allocs: 0.906 kB2 allocs: 0.906 kB1
Gamma/cdf2 allocs: 0.906 kB2 allocs: 0.906 kB1
Gamma/logccdf2 allocs: 0.906 kB2 allocs: 0.906 kB1
Gamma/logcdf2 allocs: 0.906 kB2 allocs: 0.906 kB1
Gamma/pdf2 allocs: 0.906 kB2 allocs: 0.906 kB1

Hooks

Time

Benchmarkv0.1.08400c41028f79b...v0.1.0 / 8400c41028f79b...
Gamma/ccdf_ad_safe3.65 ± 0.36 μs3.63 ± 0.36 μs1.01 ± 0.14
Gamma/cdf_ad_safe3.6 ± 0.38 μs3.57 ± 0.37 μs1.01 ± 0.15
Gamma/logccdf_ad_safe5.34 ± 0.067 μs5.33 ± 0.067 μs1 ± 0.018
Gamma/logcdf_ad_safe4.95 ± 0.21 μs4.94 ± 0.21 μs1 ± 0.06
Gamma/pdf_ad_safe4.15 ± 0.21 μs4.17 ± 0.21 μs0.993 ± 0.07
Normal (fall-through)/cdf_ad_safe1.7 ± 0.32 μs1.5 ± 0.31 μs1.14 ± 0.32
Normal (fall-through)/logcdf_ad_safe3.98 ± 0.35 μs3.94 ± 0.35 μs1.01 ± 0.13
Normal (fall-through)/pdf_ad_safe1.08 ± 0.33 μs1.09 ± 0.33 μs0.995 ± 0.43
_gamma_cdf/broadcast3.59 ± 0.36 μs3.57 ± 0.36 μs1 ± 0.14
_gamma_cdf/scalar1.55 ± 0.01 ns1.55 ± 0.009 ns1 ± 0.0087

Memory

Benchmarkv0.1.08400c41028f79b...v0.1.0 / 8400c41028f79b...
Gamma/ccdf_ad_safe2 allocs: 0.906 kB2 allocs: 0.906 kB1
Gamma/cdf_ad_safe2 allocs: 0.906 kB2 allocs: 0.906 kB1
Gamma/logccdf_ad_safe2 allocs: 0.906 kB2 allocs: 0.906 kB1
Gamma/logcdf_ad_safe2 allocs: 0.906 kB2 allocs: 0.906 kB1
Gamma/pdf_ad_safe2 allocs: 0.906 kB2 allocs: 0.906 kB1
Normal (fall-through)/cdf_ad_safe2 allocs: 0.906 kB2 allocs: 0.906 kB1
Normal (fall-through)/logcdf_ad_safe2 allocs: 0.906 kB2 allocs: 0.906 kB1
Normal (fall-through)/pdf_ad_safe2 allocs: 0.906 kB2 allocs: 0.906 kB1
_gamma_cdf/broadcast2 allocs: 0.906 kB2 allocs: 0.906 kB1
_gamma_cdf/scalar0 allocs: 0 B0 allocs: 0 B

time_to_load

Time

Benchmarkv0.1.08400c41028f79b...v0.1.0 / 8400c41028f79b...
time_to_load0.522 ± 0.0037 s0.501 ± 0.007 s1.04 ± 0.016

Memory

Benchmarkv0.1.08400c41028f79b...v0.1.0 / 8400c41028f79b...
time_to_load0.15 k allocs: 11.7 kB0.15 k allocs: 11.7 kB1

Per-benchmark timelines

<details> <summary>Show 3 plots</summary>

plot_EpiAwareADTools_1.pngplot_EpiAwareADTools_2.pngplot_EpiAwareADTools_3.png

</details>

</details>