php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #73678 Strange performance degradation
Submitted: 2016-12-07 19:39 UTC Modified: 2016-12-08 16:48 UTC
From: riggsfolly at gmail dot com Assigned:
Status: Not a bug Package: Performance problem
PHP Version: 7.1.0 OS: Windows
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: riggsfolly at gmail dot com
New email:
PHP Version: OS:

 

 [2016-12-07 19:39 UTC] 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;






Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-12-07 20:06 UTC] 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-08 11:43 UTC] ab@php.net
Same here, degradation of 7.0, neither with 7.1 or master.

Thanks.
 [2016-12-08 12:44 UTC] 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 16:48 UTC] ab@php.net
-Status: Open +Status: Not a bug
 [2016-12-08 16:48 UTC] ab@php.net
Thanks, so this is cleared.
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Fri Feb 28 18:01:26 2020 UTC