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

…hmm, that wasn't what I expected!

Wow, the #rust 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)

Follow

@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
Mastodon for Tech Folks

This Mastodon instance is for people interested in technology. Discussions aren't limited to technology, because tech folks shouldn't be limited to technology either!

We adhere to an adapted version of the TootCat Code of Conduct and follow the Toot Café list of blocked instances. Ash is the admin and is supported by Fuzzface, Brian!, and Daniel Glus as moderators.

Hosting costs are largely covered by our generous supporters on Patreon – thanks for all the help!