- Have a deeply recursive function in
- Rewrite it naively in
- Compile with `cargo build --release`
- Notice it is now 10× *slower*

…hmm, that wasn't what I expected!

Follow

Wow, the community really is amazing! I posted a fairly beginner question on r/rust just now, and within 10 minutes I got 8 comments—7 of them were attempted solutions, 6 of them were *correct* solutions, and 2 of them had full, running code samples/diffs.

And *none* of them called me dumb or implied I don't know how to program—even though I made a classic beginner mistake (solving ownership issues with excessive use of `clone()` instead of by understating my code better)

@codesections genuinely considering going rust just to be treated be like human when programming :blobshh: I'm happy for you!

@codesections It's a good thing that some programming communities are treating beginners with respect.

@codesections again, some improvements to your (new version of) code: play.rust-lang.org/?version=st (notes inline)

On my machine it is about 10% faster than your version, must be because it doesn't do the conversions between usize/i32/Option<i32> everywhere.

And again the Rust and JS versions are doing a similar number of allocations, that is why the performance is similar.

@bugaevc

Thanks! I took your changes and ran with them—new code here: gist.github.com/codesections/9.

The execution time is now ~20% of the JavaScript time (about 3% of my original version with all the `clone()`s)

Sign in to participate in the conversation
Fosstodon

Fosstodon is an English speaking Mastodon instance that is open to anyone who is interested in technology; particularly free & open source software.