arborint wrote:One question I would have about the benchmarks in question is: what version of PHP was being used. I didn't see it listed.
On my system (3.2 gig P4 under XP Pro running XAMPP Server)...
The initial test was performed on PHP 4.4.1.
Code: Select all
$cnt+=$testclass->one();
1000000 times for 2.9005510807 seconds
Function Procedural
1000000 times for 1.00571393967 seconds
Straight Procedural
1000000 times for 0.375358819962 seconds
$cnt+=test::one();
1000000 times for 1.5131418705 seconds
OOP with class instance outside loop
1000000 times for 1.4020409584 seconds
On my system (3.2 gig P4 under XP Pro running XAMPP Server)...
The same test on the same system using PHP 5.1.1
Code: Select all
$cnt+=$testclass->one();
1000000 times for 1.87981390953 seconds
Function Procedural
1000000 times for 0.762351989746 seconds
Straight Procedural
1000000 times for 0.178838014603 seconds
$cnt+=test::one();
1000000 times for 2.78865814209 seconds
OOP with class instance outside loop
1000000 times for 0.989754199982 seconds
What I find interesting that using test::one() on PHP 5.1.1 is incredably slow and the slowest method of all. There is improvement on creating a new object inside the loop.
Plus PHP 5.1.1 does seem to improve the execution speed of procedural functions and straight procedurals.
It still comes down to OOP under current and older versions of PHP are slower. Also, using a precompiler like eAccelerator doesn't help all that much. You still have the same RATIO differences in speed of execution.
arborint wrote:The idea that a complex application will be faster if written using procedural techniques rather than OOP has never really stood up.
Actually you are right as long as you are not talking about OOP usage in PHP. Using OOP programming in compiled languages like C you will not notice any difference because you do not have the same instance allocation overheads that PHP includes. Because PHP is basically an interpreted language OOP will always be slower in execution. Even after PHP has been byte-encoded using a precompiler/optimizer you will still have the same overhead problems. Maybe PHP 6 will address these issues but I have serious doubts about it at this time.