1 | if 0
|
---|
2 | % functionality test
|
---|
3 | repmat([1 2; 3 4],2,4,2,2)
|
---|
4 | repmat([1 2; 3 4],[2 4 2 2])
|
---|
5 | repmat([1 2; 3 4],2)
|
---|
6 | repmat(j,3,2)
|
---|
7 | repmat('hello',3,2)
|
---|
8 | repmat({7},3,2)
|
---|
9 | repmat(sparse(7),3,2)
|
---|
10 | end
|
---|
11 |
|
---|
12 | x = rand(300,1);
|
---|
13 | x = rand(10,1);
|
---|
14 | % run it once to load the definition
|
---|
15 | repmat(1,1,1);
|
---|
16 | niter = 100000/prod(size(x));
|
---|
17 | n = 100;
|
---|
18 | fprintf('repmat(x,1,n)\n');
|
---|
19 | tic; for i = 1:niter xrepmat(x,1,n); end; t0=toc;
|
---|
20 | fprintf('old repmat: %g\n',t0);
|
---|
21 | tic; for i = 1:niter repmat(x,1,n); end; t=toc;
|
---|
22 | fprintf('new repmat: %g (%g times faster)\n',t,t0/t);
|
---|
23 |
|
---|
24 | if 0
|
---|
25 | % repmat is faster than ones
|
---|
26 | tic; for i = 1:niter ones(300,1000); end; toc
|
---|
27 | tic; for i = 1:niter xrepmat(ones(300,1),1,1000); end; toc
|
---|
28 | tic; for i = 1:niter repmat(1,300,1000); end; toc
|
---|
29 | end
|
---|
30 |
|
---|
31 | if 0
|
---|
32 | % zeros is faster than repmat (as expected)
|
---|
33 | tic; for i = 1:niter zeros(300,1000); end; toc
|
---|
34 | tic; for i = 1:niter repmat(zeros(300,1),1,1000); end; toc
|
---|
35 | tic; for i = 1:niter xrepmat(0,300,1000); end; toc
|
---|
36 | end
|
---|
37 |
|
---|
38 | if 0
|
---|
39 | fprintf('new repmat:');
|
---|
40 | tic; for i = 1:niter repmat(x',1000,1); end; toc
|
---|
41 | fprintf('old repmat:');
|
---|
42 | tic; for i = 1:niter xrepmat(x',1000,1); end; toc
|
---|
43 | end
|
---|
44 |
|
---|
45 | if 0
|
---|
46 | fprintf('new repmat:');
|
---|
47 | tic; for i = 1:niter repmat(x,1000,1); end; toc
|
---|
48 | fprintf('old repmat:');
|
---|
49 | tic; for i = 1:niter xrepmat(x,1000,1); end; toc
|
---|
50 | end
|
---|