I wrote a little article discussing a recent post on the CrystalRuby gem: Yes, Ruby is fast, but… - DEV Community
I modded it up to be a bit more visible in feeds — I used to work at the company that runs DEV and managed to get moderator status over the #crystal tag. :-D
One important note, though, because I also ran some benchmarks when I saw John Hawthorn’s post and got a similar result: even with your attempts to avoid LLVM over-optimizing, it’s still happening. When you pass a numeric literal to the method as well as calling times
on a numeric literal, LLVM might (depending on CPU and LLVM version) optimize it all down to a single instruction. Crystal is incredibly fast, but it’s not “1 million exponential-time fib(45)
s in 1µs” fast.
Ah, fair point that I forgot to mention. I originally tested adding a call to rand
for this particular reason, and I still got a huge boost compared to JITs (and hard to tell how much of that is just the rand
call):
0.001187 0.000076 0.001263 ( 0.001300)
I also tested bigint and oh boy that was painful to watch something to consider optimizing in the future
I extended the post with these considerations.