OK, first to the question about slowdowns due to the constant update operation. If the entire progress takes only a few milliseconds, you don't need a progress bar! In general, You definitely don't need to update faster than the eye can follow. Also, if your progress bar is e.g. 150 pixels wide, you won't see a difference unless at least 100 iterations have passed. All intermediate iterations don't need to be written, right? They are just wasting computing resources.
The solution: Simply put the progress indicator in a case that is mostly not active. Two possible suggestions (see attached image):
- update only every n'th iteration (top panel), the other case is the default case and is empty.
- wait at least x milliseconds between updates (bottom panel
).
To your second questions about two loops:
It makes logically no sense to switch between showing the progress of two different loops, if both loops run in paralell (The definition of "progress" would need a politician). Either use two progress bars, one for each loop, or arrange it that loop 2 starts after loop 1 has finished. In this case, you can use e.g. a local variable. (even here you could run the progress bar to 100% in each loop, but show a text indicator on the current code section ("Executing loop 1" 0%...100%, "Executing loop 2" 0%...100%).