fzaninotto/Faker — pull request #336 by scoates (2014-05-17 01:24:45+00:00)
Title: speeds up Provider\Base\randomKey()

Today, while doing some profiling on our unit tests, I noticed that we were spending a lot of time in Faker.
Specifically, `randomKey()` was particularly slow.

I looked into the code a bit, and was surprised you weren't using `array_rand()` here, instead of the `array_keys()` + `mt_rand()` to select one of the isolated keys.

I thought there must be a reason (such as, perhaps, small arrays might perform better with your algorithm). To find out, I ran some tests and plotted the results:

![0-1000 results](https://docs.google.com/spreadsheets/d/1E6GGO3K9TbnQVARFjSG8Zq8OYPeM2sUwML-GnKd6F-w/embed/oimg?id=1E6GGO3K9TbnQVARFjSG8Zq8OYPeM2sUwML-GnKd6F-w&oid=2012738200&zx=51waklnjoi8k)

The problem is exacerbated with even more results:

![0-10,000 results](https://docs.google.com/spreadsheets/d/1E6GGO3K9TbnQVARFjSG8Zq8OYPeM2sUwML-GnKd6F-w/embed/oimg?id=1E6GGO3K9TbnQVARFjSG8Zq8OYPeM2sUwML-GnKd6F-w&oid=1773598094&zx=hzx1kkw9xs2w)

[Spreadsheet](https://docs.google.com/spreadsheets/d/1E6GGO3K9TbnQVARFjSG8Zq8OYPeM2sUwML-GnKd6F-w/edit#gid=0)

Hacked up code to provide this data:

```php