I have an inner loop which solves a simple equation using find_zero(), currently with the default Order0() method at a plausible starting value. 99.99% of the time, this works smoothly with no issues. However, occasionally this does fail to converge, and when this happens I’d like to switch method to a bisection approach with a very large interval. The obvious method would seem to be:
try result = find_zero(f, ini) catch result = find_zero(f, [0, Big_Number]) end
However, my concern is that try/catch apparently slows down code significantly (e.g. here) even when try completes successfully. This would be lethal to my code, since this inner loop is being run an awful lot. So my questions are:
- Is there still a significant performance penalty to try/catch as of 1.5.3?
- Is there another way to achieve “try algorithm A, if it fails try B” without compromising performance?