I have code in Java that has an outer loop and several nested loops. The performance is not satisfactory. What strategies can I follow to improve overall performance?
For(int I = 0; I < 20000000; < i++) // 20 million iterations in outer loop
{
For(…)
For(…)
For(…)
method...
method...
}
You are leaving out a lot of detail. However…
If the things that the 4 different
forloops do don’t have to happen in order, you could run eachforloop on a separate thread.If you have more than 1 CPU core running the code, overall performance will improve.
Other than that, the best way to know if you can improve performance is to see where time is being spent. Run your code in a profiler.