1 | % test flops for matrix operations
|
---|
2 |
|
---|
3 | niter = 50000;
|
---|
4 | a = rand(100);
|
---|
5 | a = a*a';
|
---|
6 | T = chol(a);
|
---|
7 | b = rand(100);
|
---|
8 | c = rand(rows(a),1);
|
---|
9 |
|
---|
10 | t = [];
|
---|
11 | tic; for i=1:niter a+4; end; t(1)=toc/niter;
|
---|
12 | tic; for i=1:niter a+b; end; t(2)=toc/niter;
|
---|
13 | tic; for i=1:niter a.*b; end; t(3)=toc/niter;
|
---|
14 | t_arith = mean(t);
|
---|
15 | %fprintf('average for +,*: %g\n', t_arith);
|
---|
16 | t_flop = t_arith/prod(size(a));
|
---|
17 | fprintf('time for 1 flop: %g\n', t_flop);
|
---|
18 |
|
---|
19 | tic; for i=1:niter solve_triu(T,c); end; t_solve_triu=toc/niter;
|
---|
20 | fprintf('time for solve_triu: %g\tflops = %g (should be %d)\n', t_solve_triu, t_solve_triu/t_flop, flops_solve_tri(a,c));
|
---|
21 |
|
---|
22 | niter = niter/10;
|
---|
23 | tic; for i=1:niter chol(a); end; t_chol=toc/niter;
|
---|
24 | fprintf('time for chol: %g\tflops = %g (should be %d)\n', t_chol, t_chol/t_flop, flops_chol(rows(a)));
|
---|
25 |
|
---|
26 | tic; for i=1:niter det(a); end; t_det=toc/niter;
|
---|
27 | fprintf('time for det: %g\tflops = %g (should be %d)\n', t_det, t_det/t_flop, flops_det(rows(a)));
|
---|
28 |
|
---|
29 | tic; for i=1:niter a\c; end; t_solve=toc/niter;
|
---|
30 | fprintf('time for solve: %g\tflops = %g (should be %d)\n', t_solve, t_solve/t_flop, flops_solve(a,c));
|
---|
31 |
|
---|
32 | % matrix multiply is incredibly fast
|
---|
33 | tic; for i=1:niter a*b; end; t_mtimes=toc/niter;
|
---|
34 | fprintf('time for mtimes: %g\tflops = %g (should be %d)\n', t_mtimes, t_mtimes/t_flop, flops_mul(a,b));
|
---|
35 |
|
---|
36 | niter = niter/10;
|
---|
37 | tic; for i=1:niter inv(a); end; t_inv=toc/niter;
|
---|
38 | fprintf('time for inv: %g\tflops = %g (should be %d)\n', t_inv, t_inv/t_flop, flops_inv(rows(a)));
|
---|