Req #67346 [Opn->Csd]: array_rand() performance issue
Edit report at https://bugs.php.net/bug.php?id=67346&edit=1
ID: 67346
Updated by: nikic@php.net
Reported by: v dot martyanov at drweb dot com
Summary: array_rand() performance issue
-Status: Open
+Status: Closed
Type: Feature/Change Request
Package: Arrays related
Operating System: Any
PHP Version: 5.5.12
-Assigned To:
+Assigned To: nikic
Block user comment: N
Private report: N
New Comment:
PHP 7.1 uses a significantly faster array_rand() algorithm, especially for the num_req==1 case. It
is now O(1) instead of O(n).
Previous Comments:
------------------------------------------------------------------------
[2014-05-27 11:40:19] v dot martyanov at drweb dot com
Description:
------------
There is a performance issue in array_rand(). The problem is in using doubles instead of long
integers in the source.
In the case when num_req == 1 and num_avail < 256 it's not so hard to use tables with
precomputed values and avoid the usage of divisions and doubles.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=67346&edit=1
Thread (2 messages)