Will a rust program run faster than programs written in other languages?
Thank y'all !
Will a rust program run faster than programs written in other languages?
Thank y'all !
Usually what is meant is the machine code coming out of the compiler is (roughly) equivalent to what you'd get if you wrote it by hand in assembly. There is no extra overhead because of garbage collection, invoking a JIT, or because you are actually interpreting bytecodes, using unnecessary indirection (e.g. by default, Delphi and Java typically place every object on the heap and use dynamic dispatch).
Rust doesn't magically make your code fast and you can still write slow code (e.g. using the wrong algorithm or being stupidly inefficient), but its up there with C and C++ as being one of the fastest languages around.
Thank you !!!
To add to @Michael-F-Bryan’s answer, I’d say the fast languages have one thing in common: control. That is, they allow you to control performance-impacting implementation decisions. You get memory layout control, at a minimum. For languages with sophisticated abstraction capability (eg C++ and Rust), they provide some guarantees about how the abstraction is compiled. For example, Rust generics are promised monomorphization. C++ templates are promised compile-time expansion, which for the purpose of “does the compiler see concrete types”, is equal to traits. After that, it’s essentially all about quality of the compiler(s).
Thank you !!