Mercurial > hg > smallbox
comparison Problems/private/timerinit.m @ 10:207a6ae9a76f version1.0
(none)
author | idamnjanovic |
---|---|
date | Mon, 22 Mar 2010 15:06:25 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
9:28f2b5fe3483 | 10:207a6ae9a76f |
---|---|
1 function tid = timerinit(par1,par2) | |
2 %TIMERINIT Initialize a new timer. | |
3 % TID = TIMERINIT() initializes a new timer for counting elapsed time, | |
4 % and returns its id. | |
5 % | |
6 % TID = TIMERINIT('TIMERNAME') sets the timer name to the specified | |
7 % string for display purposes. | |
8 % | |
9 % TID = TIMERINIT(ITERNUM) initializes a new ETA timer for a process with | |
10 % ITERNUM iterations. An ETA timer can be used for both counting elapsed | |
11 % time and estimating remaining time. | |
12 % | |
13 % TID = TIMERINIT('TIMERNAME',ITERNUM) sets the ETA timer name to the | |
14 % specified string for display purposes. | |
15 % | |
16 % Example: | |
17 % | |
18 % tid = timerinit(100); | |
19 % for i = 1:100 | |
20 % pause(0.07); | |
21 % timereta(tid,i,1); | |
22 % end | |
23 % timereta(tid,i); | |
24 % | |
25 % See also TIMERETA, TIMERCLEAR. | |
26 | |
27 | |
28 % Ron Rubinstein | |
29 % Computer Science Department | |
30 % Technion, Haifa 32000 Israel | |
31 % ronrubin@cs | |
32 % | |
33 % June 2008 | |
34 | |
35 | |
36 global utiltbx_timer_start_times % start times | |
37 global utiltbx_time_lastdisp % last display times | |
38 global utiltbx_timer_iternums % iteration numbers | |
39 global utiltbx_timer_lastiter % last queried iteration numbers | |
40 global utiltbx_timer_name % timer names | |
41 global utiltbx_timer_callfun % timer calling functions | |
42 | |
43 | |
44 % parse function arguments % | |
45 | |
46 if (nargin==0) | |
47 | |
48 iternum = -1; | |
49 timername = ''; | |
50 | |
51 elseif (nargin==1) | |
52 | |
53 if (ischar(par1)) | |
54 iternum = -1; | |
55 timername = par1; | |
56 | |
57 elseif (isnumeric(par1) && numel(par1)==1 && par1>0) | |
58 iternum = par1; | |
59 timername = ''; | |
60 | |
61 else | |
62 error('Invalid number of iterations'); | |
63 end | |
64 | |
65 elseif (nargin==2) | |
66 | |
67 if (ischar(par1) && isnumeric(par2)) | |
68 if (numel(par2)==1 && par2>0) | |
69 timername = par1; | |
70 iternum = par2; | |
71 else | |
72 error('Invalid number of iterations'); | |
73 end | |
74 else | |
75 error('Invalid function syntax'); | |
76 end | |
77 | |
78 else | |
79 error('Too many function parameters'); | |
80 end | |
81 | |
82 | |
83 % register the timer % | |
84 | |
85 if (isempty(utiltbx_timer_start_times)) | |
86 utiltbx_timer_start_times = clock; | |
87 utiltbx_time_lastdisp = utiltbx_timer_start_times; | |
88 utiltbx_timer_iternums = double(iternum); | |
89 utiltbx_timer_lastiter = 0; | |
90 utiltbx_timer_name = { timername }; | |
91 utiltbx_timer_callfun = {}; | |
92 tid = 1; | |
93 else | |
94 utiltbx_timer_start_times(end+1,:) = clock; | |
95 utiltbx_time_lastdisp(end+1,:) = utiltbx_timer_start_times(end,:); | |
96 utiltbx_timer_iternums(end+1) = double(iternum); | |
97 utiltbx_timer_lastiter(end+1) = 0; | |
98 utiltbx_timer_name{end+1} = timername; | |
99 tid = size(utiltbx_timer_start_times,1); | |
100 end | |
101 | |
102 | |
103 % detect timer calling function % | |
104 | |
105 st = dbstack; | |
106 if (length(dbstack) >= 2) | |
107 utiltbx_timer_callfun{end+1} = st(2).name; | |
108 else | |
109 utiltbx_timer_callfun{end+1} = ''; | |
110 end |