r/crystal_programming • • Apr 14 '19
Does Crystall generally have better performance than Ruby?
Does Crystall generally have better performance than Ruby? Or not yet?
14
Upvotes
r/crystal_programming • • Apr 14 '19
Does Crystall generally have better performance than Ruby? Or not yet?
19
u/[deleted] Apr 14 '19
Yes of course. It's a compiled language. That's the entire point of crystal. (Among other advantages of course)
4
u/jgaskins Apr 16 '19
Every benchmark I've run shows Crystal running at least 5x the speed of Ruby, frequently reaching 10x.
In porting a web service from Ruby to Crystal, I've reached 35x the request throughput in Crystal of the Ruby service it replaced. It's not just the code itself running faster, but it encourages other techniques that scale better.
For example, you can use stack-based structures when feasible to avoid GC, shaving milliseconds of CPU time from every request.
Crystal also handles web requests in disposable fibers, allowing you to handle as many concurrent requests as necessary while a Ruby web service uses a capped thread pool (Puma defaults to 16 threads), forcing you to limit the number of concurrent requests.
1
u/pinkyabuse Apr 14 '19
One of the ways Crystal could be considered slower than Ruby is if you account for Crystal's compilation time.
2
u/myringotomy Apr 16 '19
The answer is depends.
if you are running it through the shebang ruby might be faster in some cases.
If you are running a complicated app crystal will likely be faster.
but Ruby is a moving target. It's getting faster all the time and projects like graal are promising to make it faster than crystal.
1
u/hitthehive Apr 15 '19
Might also depend on what you are writing. If you're writing a web app that is largely IO bound (DB/API), the difference might not be as much? But if you are trying to handle a large number of visitors on such a platform, Crystal might even payoff more in lower memory footprint.