https://github.com/caiuspetronius/Optometrika/blame/a6c2c4db64fca033d15eea9de5d2c8edc33fb0c3/refrindx.m#L59-L80
There is a big performance loss with the cases 'air', 'mirror' & 'soot'. Optometrika currently fits a polynom to [1, 1, 1] for every ray you simulate. Instead in these cases the simple solution is just to add the lines
n_refr = ones(length(wavelength), 1);
return
This will skip the trivial solution of the polynomial. In my case the refrindx function was more than 1/3 of the overall simulation time. After the fix this time was saved and the function is now just 1-2% of the overall simulation time. This of course depends on the optics used and caching further inefficient calculations could also benefit this function.
https://github.com/caiuspetronius/Optometrika/blame/a6c2c4db64fca033d15eea9de5d2c8edc33fb0c3/refrindx.m#L59-L80
There is a big performance loss with the cases 'air', 'mirror' & 'soot'. Optometrika currently fits a polynom to [1, 1, 1] for every ray you simulate. Instead in these cases the simple solution is just to add the lines
n_refr = ones(length(wavelength), 1);returnThis will skip the trivial solution of the polynomial. In my case the refrindx function was more than 1/3 of the overall simulation time. After the fix this time was saved and the function is now just 1-2% of the overall simulation time. This of course depends on the optics used and caching further inefficient calculations could also benefit this function.