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

Iterator of ndarray has poor performance than Iterator of slice #500

Closed
tuxzz opened this issue Oct 9, 2018 · 5 comments
Closed

Iterator of ndarray has poor performance than Iterator of slice #500

tuxzz opened this issue Oct 9, 2018 · 5 comments

Comments

@tuxzz
Copy link

tuxzz commented Oct 9, 2018

I've made a simple performance test

i7-4790 3.60GHz + Windows 10 17763 + rustc 1.31.0-nightly (2bd5993ca 2018-10-02) x86_64-pc-windows-msvc

Test Time(s)
ndarray_iter 2.684
slice_iter 0.875
slice_loop_safe_good 0.298

i7-4790 3.60GHz + Windows 10 17763 + rustc 1.31.0-nightly (2bd5993ca 2018-10-02) x86_64-pc-windows-msvc + Thin LTO

Test Time(s)
ndarray_iter 1.310
slice_iter 0.776
slice_loop_safe_good 0.288
ndarray_loop_safe_good 0.133
slice_loop_unsafe_good 0.132

Iterate over a ArrayView is incredible slow than slice.
But for loop on ArrayView as fast as to get_unchecked on slice.
Maybe a bug?

@jturner314
Copy link
Member

Thanks for reporting this. Out of curiosity, how does the fn_ndarray_method_2 approach perform?

I haven't taken a look at the assembly, but I have a guess why ndarray_iter is significantly slower than slice_iter. Will you please try rerunning the benchmarks using the iter-nth branch on my fork? (It should only affect the ndarray_iter benchmark.) Add this to your Cargo.toml:

[patch.crates-io]
ndarray = { git = "https://github.com/jturner314/ndarray.git", branch = "iter-nth" }

By the way, I recommend criterion for benchmarking. It makes setting up benchmarks easy, provides statistics, and produces useful charts.

@bluss
Copy link
Member

bluss commented Oct 28, 2018

A safe for loop is as good as on a slice? This sounds good. Can you point out which code is running for that slow ndarray_iter benchmark? If it's the iterator that I suspect, with step_by, I'm not surprised we have a performance problem there

@jturner314
Copy link
Member

I suspect that this is fixed by #614.

@LukeMathWalker
Copy link
Member

I repeated the benchmark using the current master:

Test Time(s)
NDArray 1d_1d iterator 0.968
Slice 1d_1d iterator 0.816
NDArray 1d_1d high order 0.175
Slice 1d_1d safe loop_bad 0.651
NDArray 1d_1d safe loop_bad 0.819
Slice 1d_1d safe loop_good 0.233
NDArray 1d_1d safe loop_good 0.298
Slice 1d_1d unsafe loop_good 0.069
NDArray 1d_1d unsafe loop_good 0.166

The situation seems to have improved significantly (most likely thanks to #614) - should we close this?

@bluss
Copy link
Member

bluss commented Sep 8, 2019

Nice!

@bluss bluss closed this as completed Sep 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants