|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2016-12-07 20:06 UTC] nikic@php.net
[2016-12-08 11:43 UTC] ab@php.net
[2016-12-08 12:44 UTC] riggsfolly at gmail dot com
[2016-12-08 16:48 UTC] ab@php.net
-Status: Open
+Status: Not a bug
[2016-12-08 16:48 UTC] ab@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 01:00:02 2025 UTC |
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;