While there are some performance aspects that can be improved, ultimately, it's the storage of the particles that will dwarf any efforts.
Your algorithm is O(n^2)
, as for each particle, you iterate over the whole particle list again. For n = 700
, that's 700*700 = 490000
executions of the loop. Also, many particles are checked i
too often. If you start the inner loop at j=i
, you'll gain a noticeable speed up.
However, this will only be a bandaid in my opinion. You should look into a more efficient storage of your particles, namely the Quadtree.
Also, instead of calculating a sqrt for each distance, square the distance you compare against:
distTo = (xDist * xDist) + (yDist * yDist);
...
if(distanceBetween(particleList[i].position, particleList[j].position) < reactDistance * reactDistance)
You can even precalculate that before the loops so you don't have that overhead every time.