Conditional Operators vs. Polymorphism
Posted: Friday, February 12, 2010 @ 5:29 AM
Updated: Friday, February 12, 2010 @ 5:31 AM
This paper, Maintainability versus Performance: What's the Effect of Introducing Polymorphism? (by Serge Demeyer), caught my attention. The author basically runs tests against various compilers to benchmark runtime pathway execution of conditional logic vs. polymorphic types. In the 90s, conditional logic would have been the M.O. simply because of speed, as well as ease of readability some would argue. Optimizing compilers have now advanced enough it would seem to nullify this rule of thumb. Dereferencing vtable pointers and jumping has gotten faster than optimizing if-then-else control statements (or switch statements). I'll have to keep this in mind as I design future software, as I'm big on being able to modify and extend via refactoring rather than re-designing and possibly breaking the functional specification, or having to add too much cruft for backwards-compatibility. Polymorphic types allow that to be done.