comparison DL/RLS-DLA/private/timereta.m @ 60:ad36f80e2ccf

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