Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

precompute chunks #373

Merged
merged 1 commit into from
Oct 30, 2018
Merged

precompute chunks #373

merged 1 commit into from
Oct 30, 2018

Conversation

KristofferC
Copy link
Collaborator

@KristofferC KristofferC commented Oct 30, 2018

Benchmark

function rosenbrock(x)
   a = one(eltype(x))
   b = 100 * a
   result = zero(eltype(x))
   for i in 1:length(x)-1
       result += (a - x[i])^2 + b*(x[i+1] - x[i]^2)^2
   end
   return result
end

using BenchmarkTools
import ForwardDiff
const x = rand(10)
@btime ForwardDiff.gradient(rosenbrock, x)

Before

julia> @btime ForwardDiff.gradient(rosenbrock, x);
  4.484 μs (4 allocations: 2.03 KiB)

After

julia> @btime ForwardDiff.gradient(rosenbrock, x);
  851.246 ns (4 allocations: 2.03 KiB)

It feels silly this helps but numbers don't lie.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants