I want to improve the performance of my application, and found that it spends about 90% of its running time doing one of my while loops. What I basically do in this while loop is the following.
int i = 0;
while (i < 100)
1) Search a big arrayList for position of an objects timestamp.
2) Search the same arrayList for position of another objects timestamp.
3) I get this subArrayList (or timewindow).
4) The array that now is returned I iterate through and compute an average.
5) I push this average into a stack.
i++
endwhile
One iteration of this loop takes on average 1-10 milliseconds, and this whole part usually takes from 100-1000 milliseconds. From what I can understand, even tho the 99th sublist only takes about 1 ms to complete, it will have waited 99-9999 ms before it got its chance to do that, right, or am I way off here?
What I had in mind was spawning a thread and have it return its value on position i. When all threads where done, continue program.
I don't care if the average of timewindow x returns before average of timewindow y, only that all the threads/values have returned before I continue.
I got the following questions:
Would it be worthwhile to try and make every iteration a thread of some sort and compute it in parallel?
If so, would I need a thread pool, and what is the best way to go about doing that?