Warning: Division by zero in /var/customers/webs/stc/benchmark/index.php on line 256 Test: rand vs. array_rand (odd keys)

PHP Benchmarks

Performance comparison of PHP code alternatives.

Test: rand() vs. array_rand() (odd keys)

Run Again Test Menu

Result

Unfortunately, no history for this test is available.

Code

The first test, "rand()", was:

$keys = array_keys($GLOBALS['array']);
$key = rand(0, count($keys) - 1);
$GLOBALS['dummy'] = $GLOBALS['array'][$keys[$key]];

The second test, "array_rand()", was:

$key = array_rand($GLOBALS['array'], 1);
$GLOBALS['dummy'] = $GLOBALS['array'][$key];

Running: Linux (x86_64:1 GB) PHP (7.2.22-1+ubuntu16.04.1+deb.sury.org+1)