I need to permute the indexes of an array, so I found function randperm very convenient. But it turns out very slow. The following test shows time increased 60 times. Is there an alternative to permute an array?

-------------
tic()
f=0.
A=[1:100]
for i=1:10000000
    f +=  A[20]
end
toc()

elapsed time: 0.891431009 seconds

-------------
tic()
f=0.
A=[1:100]
for i=1:10000000
    A = randperm(100)
    f +=  A[20]
end
toc()

elapsed time: 60.348117087 seconds

Reply via email to