Skip to content

2d array indexing is very slow #95

@ViralBShah

Description

@ViralBShah

2d array indexing is significantly slower than matlab for us.

*** MATLAB ***

function t = mytranspose(x)
[m, n] = size(x);
t = zeros(n, m);
for i=1:n
for j=1:m
t(i,j) = x(j,i);
end
end
end

a = ones(2000,2000);
tic; mytranspose(a); toc
Elapsed time is 0.132217 seconds.

*** Julia ***

function transpose(a::Matrix)
m,n = size(a)
b = similar(a, n, m)
for i=1:m, j=1:n
b[j,i] = a[i,j]
end
return b
end

julia> x = ones(2000,2000);

julia> tic(); y = x'; toc();
elapsed time: 2.17426395416259766 sec

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions