Skip to content

Commit 5f4aaee

Browse files
committed
stopwatch function
1 parent 7bb7a29 commit 5f4aaee

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

stopwatch_output.m

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
function stopwatch_output(ind)
2+
global sw_vec;
3+
global sw_cou;
4+
fprintf('\n\n');
5+
for i = find(sw_vec)
6+
fprintf(' %d (@ %d): %.3fsecs\n', i, sw_cou(i), sw_vec(i));
7+
end
8+
end

stopwatch_start.m

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
function stopwatch_start()
2+
global sw_vec;
3+
global sw_lt; % lasttime
4+
global sw_id;
5+
global sw_cou;
6+
sw_id = tic;
7+
sw_vec = [];
8+
sw_cou = [];
9+
sw_lt = 0;
10+
end

stopwatch_toc.m

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
function stopwatch_toc(sw_ind)
2+
if sw_ind == 0
3+
global sw_id;
4+
global sw_lt;
5+
sw_lt = toc(sw_id);
6+
else
7+
global sw_id;
8+
cur_time = toc(sw_id);
9+
global sw_lt;
10+
global sw_vec;
11+
global sw_cou;
12+
if length(sw_vec) < sw_ind
13+
sw_vec(sw_ind) = 0;
14+
sw_cou(sw_ind) = 0;
15+
end
16+
sw_vec(sw_ind) = sw_vec(sw_ind) + cur_time-sw_lt;
17+
sw_cou(sw_ind) = sw_cou(sw_ind) + 1;
18+
sw_lt = cur_time;
19+
end
20+
end

0 commit comments

Comments
 (0)