On the picture you can see that some highs are generally not taken into account. In addition, often a local maximum is taken for global. It is best to specify the function explicitly, and solve it. Moreover, the mathematical apparatus in this area is severely underdeveloped.
If function is differentiable, it is certainly better to solve problem explicitly. If the function is bad, considering it an approximation we can get a lot of false highs.
View review from complexring - perhaps mathematics is developed enough.