I decided to compare the performance of using if
-based execution against actual polymorphic method calls on the big 3 Ruby implementations. The results on MRI were what I expected across all of them — that is, polymorphism being much faster. The results are across 1M objects in an array.
In the case of MRI 1.9, dynamic dispatch is 58% faster than explicit if-based branching. On JRuby, the runtimes are nearly identical. And on Rubinius, polymorphic calls are slightly faster (about 25%).
user system total real