Bug #69440 [Opn->Csd]: Perfomance of function count() with array getted by references

From: Date: Tue, 14 Apr 2015 07:00:09 +0000
Subject: Bug #69440 [Opn->Csd]: Perfomance of function count() with array getted by references
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-192031@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=69440&edit=1 ID: 69440 Updated by: nikic@php.net Reported by: mikheev at 179 dot ru Summary: Perfomance of function count() with array getted by references -Status: Open +Status: Closed Type: Bug Package: Performance problem PHP Version: 5.6.8RC1 -Assigned To: +Assigned To: nikic Block user comment: N Private report: N New Comment: Because in PHP 5 an array cannot be shared between a reference ($arr) and a value (the count() argument). This has been fixed in PHP 7, where this will be possible without copying the array. Previous Comments: ------------------------------------------------------------------------ [2015-04-13 22:39:43] mikheev at 179 dot ru Description: ------------ If I execute count($arr) from function foo(&$arr), it will have a complexity O(n) (feels like) instead of the expected O(1), where n is count of elements in array. Is it correct? Why? Test script: --------------- http://sandbox.onlinephpfunctions.com/code/f2d23edf84bbfe841d3bffda8373af8d07e51a19 Expected result: ---------------- FooWithArrayCopy: 0.00056791305541992 FooWithArrayCopy: 0.00046791305541992 Actual result: -------------- FooWithArrayCopy: 0.00056791305541992 FooWithReference: 2.7791709899902 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=69440&edit=1

« previous php.bugs (#192031) next »