Get the latest tech news
Ruby might be faster than you think
I saw a project a couple weeks back which allows writing and running Crystal methods inline inside a Ruby file. It’s a neat project, and I don’t want to take away from it but something in the README example looked off to me. require 'crystalruby' require 'benchmark' module Fibonnaci crystalize [n:
Most of the time that Array allocation doesn’t actually happen, but because in this case it’s the last line of the block, and because Ruby has an implicit return at the end of the block the Array is required (even though Integer#times doesn’t use the return we don’t yet have an optimization which “knows” that). Finally, let’s enable YJIT, Ruby’s built-in JIT compiler to see the real comparison. I thought it was notable that by making some minor tweaks to Ruby code it can now outperform a precompiled statically typed language in a purpose-built example of when it is slow.
Or read this on Hacker News