,
w=ones(1,n*(n+1)/2);
w(1+cumsum(1:n-1))=-(0:n-2);
w=cumsum(w);
Dennis n<=8, .
:
n=2000;
N=1e6/n;
tic
for k=1:N
A = repmat((1 : n)', 1, n);
A = A(triu(ones(n)) ~= 0);
end
toc
tic
for k=1:N
w=ones(1,n*(n+1)/2);
w(1+cumsum(1:n-1))=-(0:n-2);
w=cumsum(w);
end
toc
tic
for k=1:N
%// Fast vector growing
v=[];
for t = 1:n
x = 1:t;
v(end+x) = x;
end
end
toc
n=4
Elapsed time is 5.688693 seconds.
Elapsed time is 3.576366 seconds.
Elapsed time is 1.878887 seconds.
n=8
Elapsed time is 2.985184 seconds.
Elapsed time is 1.851967 seconds.
Elapsed time is 1.834574 seconds.
n=100
Elapsed time is 1.084404 seconds.
Elapsed time is 0.352033 seconds.
Elapsed time is 2.502724 seconds.
n=1000
Elapsed time is 15.625361 seconds.
Elapsed time is 3.949131 seconds.
Elapsed time is 11.497764 seconds.
n=2000
Elapsed time is 29.940548 seconds.
Elapsed time is 7.649394 seconds.
Elapsed time is 22.846367 seconds.