Borrar filtros
Borrar filtros

Progress bar takes lots of time

5 visualizaciones (últimos 30 días)
tybo1mos
tybo1mos el 5 de Feb. de 2024
Comentada: tybo1mos el 5 de Feb. de 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.

Respuesta aceptada

John D'Errico
John D'Errico el 5 de Feb. de 2024
Editada: John D'Errico el 5 de Feb. de 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 comentario
tybo1mos
tybo1mos el 5 de Feb. de 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

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Dialog Boxes en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by