3 ms·
1. There is no C function. 2. Inlining in an actual C implementation doesn't matter because there is no register pressure and each trig function generates a re
by jedbrown 17y ago
1. There is no C function.
2. Inlining in an actual C implementation doesn't matter because there is no register pressure and each trig function generates a real function call. Function calls to known addresses are really fast (~2 cycles), even indirect calls are fast compared to transcendental functions (~ 6 cycles). For comparison, the C implementation takes ~260 cycles each distance computation. This can't be improved much without vectorizing the trig functions.
- Retric 17y ago1. There is no C function. What do you call public static float distance(float latA, float lngA, float latB, float lngB) { As I said but that's not a huge deal. Yes it's not a major slowdown, but a tight inner loop with a function call is begging for an inline.
- jedbrown 17y ago> import java.util.Calendar; might be your first clue... > but a tight inner loop with a function call is begging for an inline. The loop body makes several other function calls, you would be very hard pressed to measure the difference. And if it was a C function in a larger project, you probably wouldn't want to inline it because that would slow your compile times and cause you to lose modularity (i.e. you'd have to rebuild all client code rather than just update the DSO when you optimize the distance function). This function does enough work that it doesn't deserve to be inlined.
- Retric 17y agoYep, sorry, I was not really paying attention and saw what I was expecting to see.