Richard,
On Tue, 2004-02-17 at 19:25, Richard Gintz wrote:
> Using the exact same code, I created 50 objects. It took twice as
> long in php5 as it did in the older php4.
>From what I remember the speed improvement with objects in PHP 5 was
that they would be passed by reference, which I understand to be the
case. Try passing an object to a function, modifying it, then returning
it and echoing the result. I was surprised however to hear that you
found PHP 5 to be slower, I would be interested in any benchmarking
results you have. I also decided to do a quick test.
I wanted to test some decent sized classes so I used some I have written
already. Each class inherits from the one above it (names have been
changed to protect the innocent), therefore Class is a sub-class of
ClassData, etc. up to Object. Here is the wc output for the class
files:
43 200 1355 Object.php
190 533 5311 ClassBase.php
428 1554 15648 ClassData.php
481 1274 18831 Class.php
1142 3561 41145 total
Here is the script I tested with:
<?php
include_once('Object.php');
include_once('ClassBase.php');
include_once('ClassData.php');
include_once('Class.php');
function getmicrotime() {
list($usec, $sec) = explode(' ', microtime());
return ((float)$usec + (float)$sec);
}
$script_start = getmicrotime();
for ($x = 0; $x < 100000; $x++)
$a = new Class();
echo 'Script Time: ' . sprintf('%.4f',(getmicrotime() - $script_start))
. "\n";
?>
I tried to measure only the execution time of creating 100,000 objects
as accurately as possible. Creating them in an array would have been
interesting as well, but rather memory intensive, so I decided against
it. Another note is that I did run PHP 5 in cli mode only. I installed
both copies of php as well as apache2 and Turck MM Cache through emerge
on a Gentoo system. They were compiled from source but I did not change
their optimizations from the default. Since this is a testing box PHP
is installed with pretty much everything. Disclaimers aside, below is
what I found.
PHP 4.3.4 and apache2:
Script Time: 16.0964
Script Time: 16.0322
Script Time: 16.0289
Script Time: 16.0710
Script Time: 16.0306
Average: 16.0518
PHP 4.3.4 and apache2 with Turck MMCache v2.4.6:
Script Time: 15.1848
Script Time: 15.2146
Script Time: 15.2527
Script Time: 15.2354
Script Time: 15.2507
Average: 15.2276
PHP 5.0.0RC1-dev (cli):
Script Time: 15.2346
Script Time: 15.2254
Script Time: 15.2538
Script Time: 15.2414
Script Time: 15.2554
Average: 15.2421
PHP 4 is a bit slower than PHP 5, however with an optimizer it comes to
be about the same, maybe a touch faster. If/when a PHP 5 optimizer
comes out this may change some. I hope to run more benchmarks as I have
time. Also, PHP 5 is still in Beta, and this is not even the latest
version.
Regards,
Adam
--
Adam Bregenzer
[EMAIL PROTECTED]
http://adam.bregenzer.net/
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php