Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Speed Comparisons - Procedural vs. OO in interpreted languages

Tags:

In interpreted programming languages, such as PHP and JavaScript, what are the repercussions of going with an Object Oriented approach over a Procedural approach?

Specifically what I am looking for is a checklist of things to consider when creating a web application and choosing between Procedural and Object Oriented approaches, to optimize not only for speed, but maintainability as well. Cited research and test cases would be helpful as well if you know of any articles exploring this further.

Bottom line: how big (if any) is the performance hit really, when going with OO vs. Procedural in an interpreted language?

like image 866
cmcculloh Avatar asked Aug 06 '08 03:08

cmcculloh


People also ask

Is object-oriented programming faster than procedural?

Procedural programming languages are not as faster as object-oriented. The object-oriented programming languages are faster and more effective. Procedural uses procedures, modules, procedure calls. Object-oriented uses objects, classes, messages.

What are 3 differences between OO vs procedural programming?

Procedural programming is used for designing medium-sized programs. Object-oriented programming is used for designing large and complex programs. Procedural programming uses the concept of procedure abstraction. Object-oriented programming uses the concept of data abstraction.

Is OOP slower than procedural?

program size: OOP will mean more lines of code than procedural projects. Performance: OOP programs are normally slower than procedural programs.


2 Answers

Maybe I'm crazy but worrying about speed in cases like this using an interpretive language is like trying to figure out what color to paint the shed. Let's not even get into the idea that this kind of optimization is entirely pre-mature.

You hit the nail on the head when you said 'maintainability'. I'd choose the approach that is the most productive and most maintainable. If you need speed later, it ain't gonna come from switching between procedural versus object oriented coding paradigms inside an interpreted language.

like image 126
Louis Brandy Avatar answered Oct 06 '22 15:10

Louis Brandy


Unfortunately, I've done my tests too. I did test speed, and it's about the same, but when testing for memory usage getting memory_get_usage() in PHP, I saw an overwhelmingly larger number on the OOP side.

116,576 bytes for OOP to 18,856 bytes for procedural. I know "Hardware is cheap", but come on! 1,000% increase in usage? Sorry, that's not optimal. And having so many users hitting your website at once, I'm sure your RAM would just burn, or run out. Am I wrong?

like image 44
George Avatar answered Oct 06 '22 15:10

George