Mercurial > repos > public > sbplib
comparison time.m @ 200:ef41fde95ac4 feature/beams
Merged feature/grids into feature/beams.
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Mon, 13 Jun 2016 16:59:02 +0200 |
parents | 305d8bb366ce |
children |
comparison
equal
deleted
inserted
replaced
181:419ec303e97d | 200:ef41fde95ac4 |
---|---|
1 function t_out = time(f, n) | |
2 default_arg('n',1); | |
3 | |
4 if n == 1 | |
5 t = timeOnce(f); | |
6 else | |
7 t = timeAvg(f, n); | |
8 end | |
9 | |
10 if nargout == 1 | |
11 t_out = t; | |
12 else | |
13 fprintf('Elapsed time is %.6f seconds.\n', t) | |
14 end | |
15 end | |
16 | |
17 function t = timeOnce(f) | |
18 s = tic(); | |
19 | |
20 f(); | |
21 | |
22 t = toc(s); | |
23 end | |
24 | |
25 | |
26 function t = timeAvg(f, n) | |
27 s = tic(); | |
28 | |
29 for i = 1:n | |
30 f(); | |
31 end | |
32 | |
33 t = toc(s)/n; | |
34 end |