3 ms·
A couple of notes: 1.) A simple square macro will be faster than the expt function, because expt does special calculations for dealing with decimal exponents.
by anonjon 17y ago
A couple of notes:
1.) A simple square macro will be faster than the expt function, because expt does special calculations for dealing with decimal exponents. All you really need to do is multiply it by itself. I think something like this:
(defmacro square (expression)
(let ((symb (gensym)))
`(let ((,symb ,expression))
(* ,symb ,symb))))
would work fine.
2.) you can turn degree to radian into a macro like so:
(defmacro degree-to-radian (deg)
`(the single-float (* ,deg ,(/ (coerce pi 'single-float) 180))))
And avoid a couple of function calls and some multiplication.
This way you also don't need to duplicate 'the single-float'...
On my machine, running clozure cl, this made it about 1/8th faster than the original optimized version.
3.)
I was kind of wondering, could you do this sort of computation ahead of time for varying longitudes and latitudes, then store them in a table and do a simple look up and interpolation, instead of doing a lot of trigonometry (is this technically trigonometry?) at run time?
I'm not clear on the math exactly (whether it would work in this situation), but that sort of thing is done using pre-computed tables with fairly complex polynomial equations all of the time. In the case of a web app, it might be better to do this sort of thing (ram is cheap anyway).