Effacer les filtres
Effacer les filtres

Progress bar takes lots of time

5 vues (au cours des 30 derniers jours)
tybo1mos
tybo1mos le 5 Fév 2024
Commenté : tybo1mos le 5 Fév 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
setappdata(fprog,'canceling',0);
When I uncomment the following code
waitbar(file_byte_count/waitbartotal,fprog);
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.

Réponse acceptée

John D'Errico
John D'Errico le 5 Fév 2024
Modifié(e) : John D'Errico le 5 Fév 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 commentaire
tybo1mos
tybo1mos le 5 Fév 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
waitbar(tmp/100,fprog);
waitbartmp=tmp;
end

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Dialog Boxes dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by