DEV Community

Discussion on: Implementing Merge Sort in Rust

rsalmei profile image
Rogério Sampaio de Almeida

Man, your merge has very poor performance, because you are cloning the whole array twice inside a recursive function! Every merge call, even the ones with only one element on each side, will clone the whole array twice... You could try to make it in-place, just swapping elements.
Also, it is written like in C, it could be very improved using Rust constructs, like iterators, slices, and some trait magic.
Here it is one that's very good:
I specially like the one in the comments.

felixfaisal profile image
felixfaisal Author

Hey, Thanks a lot for sharing the article, I'm still exploring Rust plus learning other things. I'm familiar with C so I was sort of seeing how it would be implemented in Rust Syntax.