oop vs procedural speed differences

liunx

Guest
Just something i was thinking about. Does anyone know if is there any lose in performance using oop over procedual programming?

Does it take longer to create and initialize a class rather then using normal functions?I would think the speed differences (if any) would be negligible, and it really depends on what is happening when the object is instantiated.i looked it up awhile ago to see. OPP in PHP is actually signifcantly slower than procedrual. in PHP5 it's even worse for some reason. it's not going to make or break your system but i would definatly not use classes for anything that isn't coreIt's a trade off in all languages. OOP generally has more abstractions than procedural code and so takes up more processor time, but at the same time the end result is generally more reusable code, meaning less development time. It's cheaper to put more memory and faster CPUs in a server than it is to hire another developer so it makes sense to use OOP techniques.

MrPotatoes - if you are that worried about 'core' code being as fast as possible you should be writing a C extension, and not PHP, since compartively PHP is far slower than C. PHP is about rapid application development on the web, a few milliseconds here or there should not really be an issue.

Of course, if you are writing a hugely CPU intensive application...then why the hell are you using PHP? :pi converted some code to oop and have noticed it being slightly slower the procedual (although it may be a placebo)

but on the flip side i can manage the code about 100 time more efficiently the the old version.

even with oop i do find php quickly becomes a hassle to maintain when building large applications. In these cases ASP.NET is much more suitable.Milliseconds here and milliseconds there are pretty much irrelevant - your speed problems (assuming you even have speed problems) are much more likely to be elsewhere.

Obviously, this is not a new question. Here are a couple of blog posts by Harry Fuecks from a year or so ago:
OOP and Performance (<!-- m --><a class="postlink" href="http://www.sitepoint.com/blogs/2005/01/11/oop-and-performance/">http://www.sitepoint.com/blogs/2005/01/ ... rformance/</a><!-- m -->)
Procedural PHP Leads to Slower Apps (<!-- m --><a class="postlink" href="http://www.sitepoint.com/blogs/2005/01/13/procedural-php-leads-to-slower-apps/">http://www.sitepoint.com/blogs/2005/01/ ... ower-apps/</a><!-- m -->)This is where a profiler can help tremendously with determining where your script bottlenecks actually lie at.
 
Back
Top