using ARSampling: ARSampler, Objective, sample!
using DifferentiationInterface, Distributions
using ForwardDiff
using Mooncake
using Enzyme
using Chairmarks
# Define function to sample from
f(x) = logpdf(Laplace(0., 0.5), x) + logpdf(Normal(0.0, 2.0), x)
const sam_forwarddiff = ARSampler(Objective(f), (-Inf, Inf), [-0.5, 0.5])
@be deepcopy(sam_forwarddiff) sample!(_, 100000, true, 25) samples=100 evals=1 seconds=1000
Benchmark: 100 samples with 1 evaluation
min 10.500 ms (19 allocs: 784.773 KiB)
median 11.018 ms (19 allocs: 784.773 KiB)
mean 11.566 ms (20.44 allocs: 785.791 KiB, 0.75% gc time)
max 66.549 ms (28 allocs: 792.625 KiB, 74.66% gc time)
sam_mooncake = ARSampler(Objective(f; adbackend = AutoMooncake()), (-Inf, Inf), [-0.5, 0.5])
@be deepcopy(sam_mooncake) sample!(_, 100000, true, 25) samples=100 evals=1 seconds=1000
Benchmark: 100 samples with 1 evaluation
min 10.474 ms (19 allocs: 784.773 KiB)
median 10.791 ms (19 allocs: 784.773 KiB)
mean 10.991 ms (20.50 allocs: 785.850 KiB, 0.81% gc time)
max 21.635 ms (28 allocs: 792.625 KiB, 47.50% gc time)
sam_mooncake = ARSampler(Objective(f; adbackend = AutoEnzyme()), (-Inf, Inf), [-0.5, 0.5])
@be deepcopy(sam_mooncake) sample!(_, 100000, true, 25) samples=100 evals=1 seconds=1000
Benchmark: 100 samples with 1 evaluation
min 10.519 ms (19 allocs: 784.773 KiB)
median 10.896 ms (19 allocs: 784.773 KiB)
mean 11.091 ms (20.38 allocs: 785.802 KiB, 0.61% gc time)
max 28.180 ms (28 allocs: 792.625 KiB, 60.57% gc time)