| So you're saying that while my suggestion apparently improves the worst-easily-found case by 3-4 orders of magnitude, it makes the average in your tests worse by 10-40%, so you don't want to do it? I suspect if you try a larger test (such as the fuzz test I sent ypou), you're find some fairly-common very bad cases that will reverse that. My suggested change may or may not be the optimal solution, but the fact remains that a worst-easily-found-case of taking >200,000 iterations to partially sort 32 objects is incredibly bad performance (worse than N^3) – your current algorithm needs to be replaced. A good fisrt place to look for a better algorithm might be https://en.wikipedia.org/wiki/Topological_sorting |