Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sparse() is slow when Range inputs are used as opposed to vectors #938

Closed
ViralBShah opened this issue Jun 17, 2012 · 5 comments
Closed
Labels
performance Must go faster

Comments

@ViralBShah
Copy link
Member

When ranges are passed to sparse(), the code runs 10 times slower.

julia> load("sparse.jl")
julia> x = 1:1000000;
julia> y = [x];
julia> @time sparse(x,x,x);
elapsed time: 0.4299280643463135 seconds
julia> @time sparse(y,y,y);
elapsed time: 0.043261051177978516 seconds
@ViralBShah
Copy link
Member Author

I am guessing this is because the codegen is optimizing A[i] for vectors, but there is no similar rule for Range.

@ViralBShah
Copy link
Member Author

This is even more surprising, since range inputs are expanded anyways in _jl_make_sparse

@ViralBShah
Copy link
Member Author

This is still the case even with the new implementation of sparse().

julia> x = 1000000:-1:1
1000000:-1:1

julia> @time sparse(x,x,x);
elapsed time: 0.3297080993652344 seconds

julia> x = [1000000:-1:1];

julia> @time sparse(x,x,x);
elapsed time: 0.09220290184020996 seconds

@JeffBezanson
Copy link
Member

Yes, ref is slower on ranges than on arrays, but iterating over them is just as fast.

@ViralBShah
Copy link
Member Author

It is a performance pothole, as people will routinely pass stuff like 1:n around. Can we improve the performance of ref on ranges, or will this be something people have to watch out for?

-viral

On 19-Jun-2012, at 10:15 AM, Jeff Bezanson wrote:

Yes, ref is slower on ranges than on arrays, but iterating over them is just as fast.


Reply to this email directly or view it on GitHub:
#938 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance Must go faster
Projects
None yet
Development

No branches or pull requests

2 participants