Skip to content

Commit

Permalink
update benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
jrevels committed Nov 2, 2016
1 parent be39cc1 commit e534cba
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 55 deletions.
94 changes: 39 additions & 55 deletions benchmark/ForwardDiffBenchmarks.jl
@@ -1,6 +1,6 @@
module ForwardDiffBenchmarks

using ForwardDiff
using ForwardDiff, DiffBase
using BenchmarkTools

include(joinpath(dirname(dirname(@__FILE__)), "test", "utils.jl"))
Expand All @@ -9,72 +9,56 @@ name(f) = last(split(string(f), '.'))

const SUITE = BenchmarkGroup()

xs = map(n -> rand(MersenneTwister(1), n), (10, 100, 1000, 10000))
chunk_sizes = 1:10
const vecs = map(n -> rand(MersenneTwister(1), n), (10, 100, 1000))
const mats = map(n -> rand(MersenneTwister(1), n, n), (5, 16, 32))

val = addgroup!(SUITE, "value")
deriv = addgroup!(SUITE, "derivative")
grad = addgroup!(SUITE, "gradient")
jac = addgroup!(SUITE, "jacobian")
hess = addgroup!(SUITE, "hessian")
const value_group = addgroup!(SUITE, "value")
const derivative_group = addgroup!(SUITE, "derivative")
const gradient_group = addgroup!(SUITE, "gradient")
const jacobian_group = addgroup!(SUITE, "jacobian")
const hessian_group = addgroup!(SUITE, "hessian")

for f in (NUMBER_TO_NUMBER_FUNCS..., NUMBER_TO_ARRAY_FUNCS...)
x = 1
val[name(f)] = @benchmarkable $(f)($x)
deriv[name(f)] = @benchmarkable ForwardDiff.derivative($f, $x)
end
for f in (DiffBase.NUMBER_TO_NUMBER_FUNCS..., DiffBase.NUMBER_TO_ARRAY_FUNCS...)
x = 1.0
y = f(x)

for f in VECTOR_TO_NUMBER_FUNCS
fval = addgroup!(val, name(f))
fgrad = addgroup!(grad, name(f))
fhess = addgroup!(hess, name(f))
for x in xs
xlen = length(x)
fval[xlen] = @benchmarkable $(f)($x)
for c in chunk_sizes
fgrad[xlen, c] = @benchmarkable ForwardDiff.gradient($f, $x, $(Chunk{c}()))
fhess[xlen, c] = @benchmarkable ForwardDiff.hessian($f, $x, $(Chunk{c}()))
end
end
end
value_group[name(f)] = @benchmarkable $(f)($x)

for (f!, f) in VECTOR_TO_VECTOR_FUNCS
fval = addgroup!(val, name(f))
fjac = addgroup!(jac, name(f))
for x in xs
xlen = length(x)
fval[xlen] = @benchmarkable $(f)($x)
for c in chunk_sizes
fjac[xlen, c] = @benchmarkable ForwardDiff.jacobian($f, $x, $(Chunk{c}()))
end
end
out = isa(y, Number) ? DiffBase.DiffResult(y, y) : DiffBase.DiffResult(similar(y), similar(y))
derivative_group[name(f)] = @benchmarkable ForwardDiff.derivative!($out, $f, $x)
end

function runafew(seconds = 1)
result = BenchmarkGroup()
for f in (DiffBase.VECTOR_TO_NUMBER_FUNCS..., DiffBase.MATRIX_TO_NUMBER_FUNCS...)
fval = addgroup!(value_group, name(f))
fgrad = addgroup!(gradient_group, name(f))
fhess = addgroup!(hessian_group, name(f))
arrs = in(f, DiffBase.VECTOR_TO_NUMBER_FUNCS) ? vecs : mats
for x in arrs
y = f(x)

deriv = addgroup!(result, "derivative")
tune!(SUITE["derivative"], seconds = seconds) # fast enough to require tuning
for (f, b) in SUITE["derivative"]
deriv[f] = run(b; seconds = seconds)
end
fval[length(x)] = @benchmarkable $(f)($x)

grad = addgroup!(result, "gradient")
for (f, group) in SUITE["gradient"]
grad[f] = run(group[1000, 10]; seconds = seconds)
end
gout = DiffBase.DiffResult(y, similar(x, typeof(y)))
gopts = ForwardDiff.Options(x)
fgrad[length(x)] = @benchmarkable ForwardDiff.gradient!($gout, $f, $x, $gopts)

hess = addgroup!(result, "hessian")
for (f, group) in SUITE["hessian"]
hess[f] = run(group[100, 10]; seconds = seconds)
hout = DiffBase.DiffResult(y, similar(x, typeof(y)), similar(x, typeof(y), length(x), length(x)))
hopts = ForwardDiff.HessianOptions(hout, x)
fhess[length(x)] = @benchmarkable ForwardDiff.hessian!($hout, $f, $x, $hopts)
end
end

jac = addgroup!(result, "jacobian")
for (f, group) in SUITE["jacobian"]
jac[f] = run(group[1000, 10]; seconds = seconds)
end
for f in DiffBase.ARRAY_TO_ARRAY_FUNCS
fval = addgroup!(value_group, name(f))
fjac = addgroup!(jacobian_group, name(f))
for x in mats
y = f(x)
fval[length(x)] = @benchmarkable $(f)($x)

return result
out = DiffBase.JacobianResult(y, x)
opts = ForwardDiff.Options(x)
fjac[length(x)] = @benchmarkable ForwardDiff.jacobian!($out, $f, $x, $opts)
end
end

end # module
Binary file removed benchmark/results_julia_v04_forwarddiff_v01.jld
Binary file not shown.
Binary file removed benchmark/results_julia_v04_forwarddiff_v02.jld
Binary file not shown.
Binary file removed benchmark/results_julia_v05_forwarddiff_v02.jld
Binary file not shown.

0 comments on commit e534cba

Please sign in to comment.