Bug #73678 [Opn->Nab]: Strange performance degradation
| From: | ab@php.net | Date: | Thu, 08 Dec 2016 16:48:12 +0000 |
| Subject: | Bug #73678 [Opn->Nab]: Strange performance degradation | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-205855@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=73678&edit=1
ID: 73678
Updated by: ab@php.net
Reported by: riggsfolly at gmail dot com
Summary: Strange performance degradation
-Status: Open
+Status: Not a bug
Type: Bug
Package: Performance problem
Operating System: Windows
PHP Version: 7.1.0
Block user comment: N
Private report: N
New Comment:
Thanks, so this is cleared.
Previous Comments:
------------------------------------------------------------------------
[2016-12-08 12:44:21] riggsfolly at gmail dot com
Hi Guys,
Yes, very sorry for wasting your time.
As suggested XDEBUG was involved, and was the reason for the timings.
Run without XDEBUG and received very similiar timings to yours.
Still I learnt something from this, XDEBUG does carry a suprisingly large overhead.
Without XDEBUG
7.1.0
Using (object) [] method 10000000 times 1.8600029945374
Using new stdClass() method 10000000 times 3.200003862381
Difference (-ve) means (object) [] is quicker -1.3400008678436
7.0.14
Using (object) [] method 10000000 times 2.5900039672852
Using new stdClass() method 10000000 times 3.7700049877167
Difference (-ve) means (object) [] is quicker -1.1800010204315
In fact 7.1.0 seems to be faster that 7.0.14
------------------------------------------------------------------------
[2016-12-08 11:43:37] ab@php.net
Same here, degradation of 7.0, neither with 7.1 or master.
Thanks.
------------------------------------------------------------------------
[2016-12-07 20:06:15] nikic@php.net
Cannot reproduce.
Ubuntu:
PHP 7.0:
nikic@saturn:~/php-7.0-fast$ sapi/cli/php -n t007.php
Using (object) [] method 10000000 times 0.77149391174316
Using new stdClass() method 10000000 times 1.3405849933624
PHP 7.1:
Using (object) [] method 10000000 times 0.71639490127563
Using new stdClass() method 10000000 times 1.1726460456848
Windows (x64 nts):
PHP 7.0:
Using (object) [] method 10000000 times 1.0753118991852
Using new stdClass() method 10000000 times 1.6590139865875
PHP 7.1:
Using (object) [] method 10000000 times 0.99693298339844
Using new stdClass() method 10000000 times 1.4866938591003
Please make sure that you do not have XDebug enabled.
------------------------------------------------------------------------
[2016-12-07 19:39:42] riggsfolly at gmail dot com
Description:
------------
I was using this script to benchmark a question on StackOverflow and I noticed that in PHP 7.1.0 the
creation of a stdClass() object increased in time taken by an appreciable amount between PHP7.0.13
and PHP7.1.0
This seemed rather odd based on all the speed improvment work done in 7.0 and 7.1 so I thought I
would report it, in case it pointed someone at something that may have changed in 7.1 to the damage
a speed improvement.
Results for different versions of PHP
PHP7.1.0
Using (object) [] method 10,000,000 times 22.970033168793
Using new stdClass() method 10,000,000 times 38.114390850067
Difference (-ve) means (object) [] is quicker -15.144357681274
PHP7.0.13
Using (object) [] method 10,000,000 times 22.230031967163
Using new stdClass() method 10,000,000 times 29.300040960312
Difference (-ve) means (object) [] is quicker -7.0700089931488
PHP5.6.25
Using (object) [] method 10,000,000 times 47.920066833496
Using new stdClass() method 10,000,000 times 54.20007610321
Difference (-ve) means (object) [] is quicker -6.2800092697144
PHP5.5.36
Using (object) [] method 10,000,000 times 46.450064897537
Using new stdClass() method 10,000,000 times 53.110074043274
Difference (-ve) means (object) [] is quicker -6.6600091457367
Test script:
---------------
function one() {
$obj = (object) ['prop1' => 1, 'prop2' => 2];
return $obj;
}
function two() {
$obj = new stdClass();
$obj->prop1 = 1;
$obj->prop2 = 2;
return $obj;
}
$looper = 10000000;
$a = microtime(1);
for ( $i=0; $i < $looper; $i++) { $x = one(); }
$b = microtime(1);
$c = $b-$a;
echo "Using (object) [] method $looper times " . $c . PHP_EOL;
$a = microtime(1);
for ( $i=0; $i < $looper; $i++) { $x = two(); }
$b = microtime(1);
$d = $b-$a;
echo "Using new stdClass() method $looper times " . $d . PHP_EOL;
echo 'Difference (-ve) means (object) [] is quicker ' . ($c - $d) . PHP_EOL;
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=73678&edit=1