Progress bar takes lots of time

9 visualizzazioni (ultimi 30 giorni)
tybo1mos il 5 Feb 2024
Commentato: tybo1mos il 5 Feb 2024
I have a parsing script which i'm trying to speed up using the Code Profiler.
The Profiler summary indicates that the wait bar is taking up more than 1/2 the total routine time.
Waitbar is initialized like this:
waitbartotal = finfo.bytes;
fprog = waitbar(0,'Please Wait, Parsing...',...
'CreateCancelBtn','setappdata(gcbf,''canceling'',1)'); % Create a progress bar to show file processing progres
When I uncomment the following code
my Rotine takes 227seconds to run vs ~40seconds with this commented out.
The call for the waitbar is located at the bottom of a while statment which reads through a file. Its called 434835 times (in this small example).
Looking for some ideas to show the progress bar more efficiently.

Risposta accettata

John D'Errico
John D'Errico il 5 Feb 2024
Modificato: John D'Errico il 5 Feb 2024
Yes, a waitbar takes time to update. It looks like you are calling it a lot. And every time, it does an update. And since this is a graphics object, it takes time, serious time.
A simple solution is to filter those calls. Only update the waitbar infrequently. If I know I am going to call it roughly 100000 times, I'll skip the call almost always. Update it once every 100 or 1000 or 10000 times in your progress.
You can do that by writing a wrapper for the waitbar. It can use a persistent counter variable that is updated, but only actually calls the waitbar every x number of calls. This would be easy to write.
  1 Commento
tybo1mos il 5 Feb 2024
Thanks. I ended up doing something like this. Might not be the ideal way, but definetly speed things up
tmp=round((file_byte_tot/waitbartotal)*100,0); % Round progress to the nearest 1 perecent
if tmp~=waitbartmp % If precentange has chagned, then update progress bar

Accedi per commentare.

Più risposte (0)


Scopri di più su Dialog Boxes in Help Center e File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by