Skip to content

Instantly share code, notes, and snippets.

@hyobyun
Created June 24, 2013 16:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hyobyun/5851485 to your computer and use it in GitHub Desktop.
Save hyobyun/5851485 to your computer and use it in GitHub Desktop.
Outputs a progress report w/ percent complete and estimated time till completion. Supply start time, iteration #, number of total iterations. Accuracy improves over iterations. Works best when iteration time does not change over time.
function time = progress( startT, i, N )
% PROGRESS
% Outputs estimated time and percentage till completion
% To use, before loop, save startT ( startT=clock; )
% then, inside loop, call progress using following variables:
% startT : beginning time defined above using clock
% i : ith iteration
% N : total number of expected iterations
%
% Hyo Byun
% Mayberg Lab, Emory University
% 2013
currentT=clock;
percentComplete=i/N*100;
timeLeftSecs=etime(currentT,startT)*(N/i)-etime(currentT,startT);
timeString='';
nhours = 0;
nmins = 0;
if timeLeftSecs >= 3600
nhours = floor(timeLeftSecs/3600);
end
if timeLeftSecs >= 60
nmins = floor((timeLeftSecs - 3600*nhours)/60);
end
nsecs = timeLeftSecs - 3600*nhours - 60*nmins;
timeString = [sprintf('%02.0f',nhours) ':' sprintf('%02.0f',nmins) ':' sprintf('%02.0f',nsecs) ''];
fprintf('%2.2f%% | %s \n', percentComplete, timeString );
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment