Can I expect ForwardDiff to give the same performance in this case?

The Performance Tips (Performance Tips · The Julia Language) in the Julia docs is a great resource. For example, here you are using non-const globals (aD and df) which are actually the first things the guide suggests to avoid.

However, AD is not always as fast as manual written derivatives. In this case in particular, I think the literal ^3 in the analytical derivative will be unrolled while this will not happen in the AD case.

2 Likes