Chapter . Ruby’s Interpreter Is Slow

Yes it is. And I’m not the only one who thinks so. Even the creator of Ruby, Yukihiro Matsomoto (a.k.a. matz), has publicly stated this. Apart from benchmarking some algorithms in Ruby and comparing the results with implementations of the same algorithm in other languages, one can look at the source code of Ruby’s interpreter and derive some reasons why it is slower than interpreters of comparable languages (e.g., Perl and Python).

Ruby’s interpreter does not compile the source code into instructions for a virtual machine. Instead, Ruby uses abstract syntax trees to represent code internally. Traversing a tree structure at runtime is known to be slower than interpreting a linear sequence of virtual machine instructions. ...

Get Addison-Wesley Professional Ruby Series Writing Efficient Ruby Code now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.