public:matlab_tips
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
public:matlab_tips [2016/04/04 14:50] – old revision restored (2016/04/02 07:41) fangfufu | public:matlab_tips [2018/03/31 00:38] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 12: | Line 12: | ||
</ | </ | ||
- | ===== Highly unscientific benchmark of prod() | + | ===== GPU / Host Performance |
- | ==== Sparse vs Dense ==== | + | These results were obtained using [[https://uk.mathworks.com/ |
- | <code matlab> | + | ^ ^Results |
- | >> a = rand(1000); | + | ^Device |
- | >> b = eye(1000); | + | ^TITAN Xp |422.47 |371.37 |207.24 |11607.69|1426.76 |763.56| |
- | >> c = sparse(a); | + | ^GeForce GTX 1080 |280.84 |223.05 |
- | >> d = sparse(b); | + | ^Core i7-4900MQ |
- | >> tic; for i = 1:10000; prod(a); end; toc | + | ^GeForce GT 730M |27.43 |25.43 |10.54 |346.57 |214.98 |
- | Elapsed time is 7.212577 seconds. | + | |
- | >> tic; for i = 1:10000; prod(b); end; toc | + | |
- | Elapsed time is 3.566560 seconds. | + | |
- | >> tic; for i = 1:10000; prod(c); end; toc | + | |
- | Elapsed time is 27.455137 seconds. | + | |
- | >> tic; for i = 1:10000; prod(d); end; toc | + | |
- | Elapsed time is 0.030041 seconds. | + | |
- | >> tic; for i = 1:10000; prod(a); end; toc | + | |
- | Elapsed time is 7.250969 seconds. | + | |
- | >> tic; for i = 1:10000; prod(b); end; toc | + | |
- | Elapsed time is 3.645549 seconds. | + | |
- | >> tic; for i = 1:10000; prod(c); end; toc | + | |
- | Elapsed time is 27.538796 seconds. | + | |
- | >> tic; for i = 1:10000; prod(d); end; toc | + | |
- | Elapsed time is 0.029214 seconds. | + | |
- | >> | + | |
- | >> n = 100000; | ||
- | >> a = rand(n,1); | ||
- | >> b = 1; | ||
- | >> tic; for i = 1:n; prod(a); end; toc; | ||
- | Elapsed time is 4.849304 seconds. | ||
- | >> tic; for i = 1:n; b = b * prod(a(i)); end; toc | ||
- | Elapsed time is 0.004573 seconds. | ||
- | >> | ||
- | </ | ||
- | |||
- | ==== Prod vs repeated multiplication ==== | ||
- | === Script === | ||
- | <code matlab> | ||
- | clear; | ||
- | n = 10000; | ||
- | a = rand(n,1) * exp(1); | ||
- | b = 1; | ||
- | |||
- | tic; | ||
- | for i = 1:n; | ||
- | c = prod(a); | ||
- | end; | ||
- | toc; | ||
- | |||
- | tic; | ||
- | for j = 1:n | ||
- | for i = 1:n; | ||
- | b = b * a(i); | ||
- | end; | ||
- | end | ||
- | toc; | ||
- | </ | ||
- | === Results === | ||
- | <code matlab> | ||
- | >> test | ||
- | Elapsed time is 0.168450 seconds. | ||
- | Elapsed time is 1.003991 seconds. | ||
- | </ | ||
- | Note that with repeated multiplication your numerical accuracy will suffer too! |
public/matlab_tips.1459781435.txt.gz · Last modified: 2018/03/31 00:38 (external edit)