I would very much like to know what exactly makes Crystal faster than Ruby while code is so similar. The short answer could be that it is compiled, and Ruby is interpreted, yet I would like to understand more about the language specifications.
Developers describe Crystal as "Fast as C, slick as Ruby". Crystal is a programming language that resembles Ruby but compiles to native code and tries to be much more efficient, at the cost of disallowing certain dynamic aspects of Ruby.
The answer is simple: people say ruby is slow because it is slow based on measured comparisons to other languages.
The results show that Crystal can be considered a fast programming language. While C with all optimisations of gcc is still faster, the per- formance of Crystal is comparable with Go. As expected is Ruby, with just-in-time (JIT) compilation or without, by a factor of 8 respectively 9 slower than Crystal.
Crystal, on the other hand, comes with all the good parts of Ruby but none of its drawbacks. Crystal's syntax is almost identical to Ruby's. This code snippet is identical for both Ruby and Crystal. Due to the similar syntax, it is an absolute breeze to migrate from one to the other.
I guess it's a combination of things:
to_s(io)
writes to an IO instead of converting the object to a string in memory. Or we have tuples for fixed-sized arrays that are allocated on the stack. Or you can declare a type as a struct to avoid heap allocations.Probably there are many more reasons, but they are related.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With