php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #67346 array_rand() performance issue
Submitted: 2014-05-27 11:40 UTC Modified: 2017-03-11 18:15 UTC
From: v dot martyanov at drweb dot com Assigned: nikic (profile)
Status: Closed Package: Arrays related
PHP Version: 5.5.12 OS: Any
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: v dot martyanov at drweb dot com
New email:
PHP Version: OS:

 

 [2014-05-27 11:40 UTC] 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.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-03-11 18:15 UTC] nikic@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: nikic
 [2017-03-11 18:15 UTC] nikic@php.net
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).
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri May 17 06:01:34 2024 UTC