Jon Swanson wrote:However, the program is time-sensitive and I have found ArrayList<Double> to be a lot slower than double. So I tried to create the equivalent with double arrays. That doesn't quite work. I know the problem, there is an Arrays.binarySearch(double a, double b) but not one with a comparator. For that I need to use objects.
I'm concerned if I go from double to Double I'll start taking the performance hits I saw with ArrayList<Double>. So can anyone tell me a) is there a better (fastest execution) way to find the index of the element closest to x in a double array and b) what sort of performance differences there might be between Double and double?
Jon Swanson wrote:Here are the timing tests on the ArrayList<Double>, Double and double, just doing the search. I created an array of 1000 elements with values from 0 to 999 and searched for 25.5, 500.1 and 975.9. The worst performance was for 25.5, so I will report that.
ArrayList<Double> 72 ms forward 28 ms reverse
Jon Swanson wrote:Nothing fancy at all. For my really long processes, i.e. seconds, it seems to be reporting timings that are consistent to what I observe in practice. Would you be willing to run it on your old Dell? Or should I add some loops around each binarySearch to get a more accurate average time?
You’re sure it wan’t 5.34649 and 18.866 ns?
Jeff Verdegan wrote: . . .
. . .
nanosPerSearch: 19.865068028600355 . . .
Jon Swanson wrote:Thanks for running the tests for me. I wrapped the binarySearch in a loop and then looked at the worst case times on my arrays of 1000 numbers.