annotate examples/private/timereta.m @ 5:f44689e95ea4

(none)
author idamnjanovic
date Mon, 22 Mar 2010 10:43:01 +0000
parents 7750624e0c73
children
rev   line source
idamnjanovic@1 1 function varargout = timereta(tid,iter,delay)
idamnjanovic@1 2 %TIMERETA Estimated remaining time.
idamnjanovic@1 3 % S = TIMERETA(TID,ITER) returns the estimated remaining time (in
idamnjanovic@1 4 % seconds) for the process associated with timer TID, assuming the
idamnjanovic@1 5 % process has completed ITER iterations. Note: the function will exit
idamnjanovic@1 6 % with an error if the timer TID does not have an associated number of
idamnjanovic@1 7 % iterations (see function TIMERINIT).
idamnjanovic@1 8 %
idamnjanovic@1 9 % [H,M,S] = TIMERETA(TID,ITER) returns the estimated remaining time in
idamnjanovic@1 10 % hours, minutes and seconds.
idamnjanovic@1 11 %
idamnjanovic@1 12 % TIMERETA(TID,ITER), with no output arguments, prints the estimated
idamnjanovic@1 13 % remaining time to the screen. The time is displayed in the format
idamnjanovic@1 14 %
idamnjanovic@1 15 % TIMERNAME: iteration ITER / ITERNUM, estimated remaining time: HH:MM:SS.SS
idamnjanovic@1 16 %
idamnjanovic@1 17 % If the timer has no assigned name, the display format changes to
idamnjanovic@1 18 %
idamnjanovic@1 19 % Iteration ITER / ITERNUM, estimated remaining time: HH:MM:SS.SS
idamnjanovic@1 20 %
idamnjanovic@1 21 % TIMERETA(TID,ITER,DELAY) only displays the remaining time if the
idamnjanovic@1 22 % time elapsed since the previous printout is at least DELAY seconds.
idamnjanovic@1 23 %
idamnjanovic@1 24 % See also TIMERINIT, TIMERCLEAR.
idamnjanovic@1 25
idamnjanovic@1 26
idamnjanovic@1 27 % Ron Rubinstein
idamnjanovic@1 28 % Computer Science Department
idamnjanovic@1 29 % Technion, Haifa 32000 Israel
idamnjanovic@1 30 % ronrubin@cs
idamnjanovic@1 31 %
idamnjanovic@1 32 % June 2008
idamnjanovic@1 33
idamnjanovic@1 34
idamnjanovic@1 35 global utiltbx_timer_start_times
idamnjanovic@1 36 global utiltbx_timer_iternums
idamnjanovic@1 37 global utiltbx_timer_lastiter
idamnjanovic@1 38 global utiltbx_time_lastdisp
idamnjanovic@1 39 global utiltbx_timer_name
idamnjanovic@1 40
idamnjanovic@1 41
idamnjanovic@1 42 if (tid<1 || tid>length(utiltbx_timer_iternums))
idamnjanovic@1 43 error('Unknown timer id');
idamnjanovic@1 44 end
idamnjanovic@1 45
idamnjanovic@1 46 if (utiltbx_timer_iternums(tid) < 0)
idamnjanovic@1 47 error('Specified timer does not have an associated number of iterations');
idamnjanovic@1 48 end
idamnjanovic@1 49
idamnjanovic@1 50 % update last reported iteration number
idamnjanovic@1 51 utiltbx_timer_lastiter(tid) = iter;
idamnjanovic@1 52
idamnjanovic@1 53 % compute elapsed time
idamnjanovic@1 54 starttime = utiltbx_timer_start_times(tid,:);
idamnjanovic@1 55 currtime = clock;
idamnjanovic@1 56 timediff = etime(currtime, starttime);
idamnjanovic@1 57
idamnjanovic@1 58 % total iteration number
idamnjanovic@1 59 iternum = utiltbx_timer_iternums(tid);
idamnjanovic@1 60
idamnjanovic@1 61 % compute eta
idamnjanovic@1 62 timeremain = (iternum-iter)*timediff/iter;
idamnjanovic@1 63
idamnjanovic@1 64 % return eta in seconds
idamnjanovic@1 65 if (nargout==1)
idamnjanovic@1 66 varargout{1} = timeremain;
idamnjanovic@1 67
idamnjanovic@1 68 % return eta in hms
idamnjanovic@1 69 elseif (nargout==3)
idamnjanovic@1 70 [varargout{1}, varargout{2}, varargout{3}] = secs2hms(timeremain);
idamnjanovic@1 71
idamnjanovic@1 72
idamnjanovic@1 73 % print eta
idamnjanovic@1 74 elseif (nargout==0)
idamnjanovic@1 75
idamnjanovic@1 76 % check last display time
idamnjanovic@1 77 lastdisptime = utiltbx_time_lastdisp(tid,:);
idamnjanovic@1 78 if (nargin>2 && etime(currtime,lastdisptime) < delay)
idamnjanovic@1 79 return;
idamnjanovic@1 80 end
idamnjanovic@1 81
idamnjanovic@1 82 % update last display time
idamnjanovic@1 83 utiltbx_time_lastdisp(tid,:) = currtime;
idamnjanovic@1 84
idamnjanovic@1 85 % display timer
idamnjanovic@1 86 [hrs,mins,secs] = secs2hms(timeremain);
idamnjanovic@1 87 if (isempty(utiltbx_timer_name{tid}))
idamnjanovic@1 88 printf('Iteration %d / %d, estimated remaining time: %02d:%02d:%05.2f', iter, iternum, hrs, mins, secs);
idamnjanovic@1 89 else
idamnjanovic@1 90 timername = utiltbx_timer_name{tid};
idamnjanovic@1 91 printf('%s: iteration %d / %d, estimated remaining time: %02d:%02d:%05.2f', timername, iter, iternum, hrs, mins, secs);
idamnjanovic@1 92 end
idamnjanovic@1 93
idamnjanovic@1 94 % invalid number of outputs
idamnjanovic@1 95 else
idamnjanovic@1 96 error('Invalid number of output arguments');
idamnjanovic@1 97 end
idamnjanovic@1 98