4 ms·
Last time I looked (which was a while back) both Go and Rust binaries for "Hello world" were over a megabyte with out-of-the-box settings, compared to just a fe
by nineteen999 8y ago
Last time I looked (which was a while back) both Go and Rust binaries for "Hello world" were over a megabyte with out-of-the-box settings, compared to just a few kilobytes for C and slightly more for C++. I should qualify that they were the simplest of Hello world programs, I didn't add any fancy options to try and reduce the size at all.
I'd be keen to see what the smallest binaries the reference implementations of these languages can produce are.
- steveklabnik 8y agoRust's standard library is statically linked, C's is not. You have to compare the total size. Additionally, Rust includes jemalloc by default on many platforms. If you really want to get extreme with this, http://mainisusuallyafunction.blogspot.com/2015/01/151-byte-static-linux-binary-in-rust.html http://mainisusuallyafunction.blogspot.com/2015/01/151-byte-..., while a bit old, talks about various things that are still true, though some stuff has changed a bit. There's also https://www.rust-lang.org/en-US/faq.html#why-do-rust-programs-have-larger-binary-sizes-than-C-programs https://www.rust-lang.org/en-US/faq.html#why-do-rust-program... Additionally, some people have done more work since then; the smallest binary rustc has ever produced is now 145 bytes: https://github.com/tormol/tiny-rust-executable https://github.com/tormol/tiny-rust-executable
- nineteen999 8y agoThanks - yes I meant to mention, that statically linked (and stripped of symbols) I get 745k for the C hello world with gcc 7.2, so the gap isn't as big as all that. I understand that shared libraries/dynamic linking is still a WIP for rust so it's not exactly a fair comparison yet. With a shared standard library you also get the benefit of having the RAM shared across multiple processes. The 145 byte example also not being a fair comparison, since you've left out the standard library! Obviously C can do that too, but it's pretty neat to see the progress rust is making. (anyway, I'm going off topic since we're discussing kernel programming here).
- steveklabnik 8y agoDon't forget that the stripping also isn't automatic on the Rust side either, so you have to do that if you do it for the C :)