3 ms·
C++ compiles down to 90 lines of ASM. https://godbolt.org/z/YYaK8f9rz https://godbolt.org/z/YYaK8f9rz Rust compiles down (up?) to 1428! https://godbolt.org/z
by itishappy 4y ago
C++ compiles down to 90 lines of ASM.
https://godbolt.org/z/YYaK8f9rz https://godbolt.org/z/YYaK8f9rz
Rust compiles down (up?) to 1428!
https://godbolt.org/z/91YfzT5fb https://godbolt.org/z/91YfzT5fb
Thanks, I hate it! Do dynamic typing next!
- scotty79 4y agoFor that small price you get security against everything except memory leaks (which you don't get anyways in this bare C++ either) not to mention other Rust niceties while keeping superficially same convenient semantics.
- stoddardlabs 4y agoYou know, you don’t NEED to qualify every slightly negative comment about Rust (especially when the comment is made in jest)
- scotty79 4y agoI am afraid that I'm just like that. When people jest with me in the real life I often choose to respond as if it was said seriously. I mean, I don't get upset or anything. Just refuse to recognize something as a jest and respond charitably but seriously as if someone was only half-joking. Not sure why I do that. I think I feel that's the best I can do for someone who attempted humor in a way that fell flat on me. I'm not talking about GP right now. "Thanks, I hate it." actually made me smirk a little bit and his links to assembly were actually super informative. So in this case humor was great but there was also substance which I felt I need to respond to with "what's in it for me".
- worldsavior 4y agoIt's because of the libraries. They get compiled once.
- steveklabnik 4y agoIt’s because they don’t have the same semantics, you are adding overhead with the Rust version in multiple ways.
- scotty79 4y agoI wonder how much difference there would be if I used shared_ptr in C++ instead of the bare one. EDIT: As far as I can tell less than 190 lines of asm but I don't know shared_ptr enough to produce exactly the same code.
- steveklabnik 4y agoYeah, that gets closer for sure. refcell is still going to add a bit of state to the value inside of the allocation, but at least the shared_ptr and Rc/Arc bits are the same semantic, so it'll be closer!
- worldsavior 4y agoLook at the asm code of rust. You would see that most of the code there is the libraries (and yeah, also because of the semantics, which are powerful).
- steveklabnik 4y ago... the library that implements those different semantics. If you wrote your own Rc and RefCell, that code would still exist, in your crate. Where it lives isn't the root cause.
- deleted 4y ago[deleted]
- doodlesdev 4y agoIf you enable optimizations it gets reduced to 200 lines. C++ -O1 reduces it to 30 lines of ASM. Both are awful, just do normal Rust or use something else entirely. I also believe they would be much closer if the C++ example used shared pointer.