The Server Pages
:: TSP Menu
- Home
- Authors
- Glossary
- RSS Feed

:: Servers
- CPanel
- Hosting
- Linux
- Windows

:: Webmaster
- Databases
- Design
- Search Engines

:: Scripts
- Scripts

:: Documentation
- PHP Manual

:: Other
- Errors & Solutions
- TechPunt
- Wojjie

Search Site w/ Google


TheServerPages Articles







Performance of OOP PHP versus non-OOP

Author: Wojjie     Posted: (2004-05-13)     Viewed: (11925 times)


There has been a debate among various groups wether it is better to use Object Oriented Programming (OOP) for developing web applications or not. It is possible to develop applications that perform the same tasks wether you decide to use OOP or not, so what does it come down to? In this article we will be making a comparision between the two in terms of performance/speed. We will not be making any conclusions here as to which is better, since that would require a more lengthy comparision.

I have previously written an article on this matter, but the test I used was controversial.

Server Specs:

Dual Xeon 2.8ghz, 2GB ECC RAM
PHP 4.3.4
Zend Engine v1.3.0
  with Zend Extension Manager v1.0.1
  with Zend Optimizer v2.5.0

PHP OOP Test Script (Script A)
function getmicrotime() //grabbed from documentation
   list($usec, $sec) = explode(" ", microtime());
   return ((float)$usec + (float)$sec);

class basket {
        var $apples;

        function basket($apples) {

        function addApple() {

$b1=new basket(10); // start with 10 apples

$t1=getmicrotime(); // start stopwatch
for ($i=0; $i<50000; $i++) {
$t2=getmicrotime(); //stop stopwatch

echo ($t2-$t1); //result time

PHP non-OOP Test Script (Script B)
function getmicrotime() //grabbed from documentation
   list($usec, $sec) = explode(" ", microtime());
   return ((float)$usec + (float)$sec);

function addApple($basket) {
        return $basket++;

$b1=10; // start with 10 apples

for ($i=0; $i<50000; $i++) {

echo ($t2-$t1); //result time


In the two tests, we are testing the execution time of functions and class functions. In an attempt to make both tests equal, I programmed both test scripts in a manner that can be used for the same applications. Both scripts can create 'baskets' and increment the number of apples in each of those baskets. To make things simple, we will only be testing the execution time of one function, incrementing the number of apples.

Since times may vary from test to test, I have decided to run this test multiple times, and also alternating the test scripts. (ie: A B A B ...)


Finally, here are the results in a table format:


OOP Average:0.31777
Non-OOP Average:0.28087

Therefore OOP comes out to be 13% slower than Non-OOP.


Copyright © 2004-2015: