Rev | Line | |
---|
[37] | 1 | % timing test for row_sum
|
---|
| 2 |
|
---|
| 3 | % each trial should take the same amount of time
|
---|
| 4 | % if not, then you are not managing the cache properly
|
---|
| 5 | tim = [];
|
---|
| 6 | for k = 1:6
|
---|
| 7 | x = randn(1024*k/4, 400);
|
---|
| 8 | niter = floor(120/k);
|
---|
| 9 |
|
---|
| 10 | tic; for i = 1:niter sum(x,2); end; tim(k,1) = toc;
|
---|
| 11 | tic; for i = 1:niter row_sum(x); end; tim(k,2) = toc;
|
---|
| 12 | tic; for i = 1:niter x*ones(cols(x),1); end; tim(k,3) = toc;
|
---|
| 13 | tic; for i = 1:niter sum(x')'; end; tim(k,4) = toc;
|
---|
| 14 | end
|
---|
| 15 | figure(1)
|
---|
| 16 | clf
|
---|
| 17 | plot(tim)
|
---|
| 18 | xlabel('trial')
|
---|
| 19 | ylabel('time (sec)')
|
---|
| 20 | legend('sum(x,2)', 'rowsum', 'product', 'sum(x'')''', 2)
|
---|
| 21 | tim(end,1)
|
---|
Note: See
TracBrowser
for help on using the repository browser.