Result: SavedThe test labeled "rand()" was the faster by 0.0165 seconds, (1.647% faster)
The rand() test took 0.9853 seconds.
The array_rand() test took 1.0018 seconds.
Each test case ran 20 random code order iterations consisting of 277,768 loops for a total of 5,555,360 runs.
- Line execution difference (0.000003) milliseconds.
- Avg difference (0.825) milliseconds per 277,768 loops.
- Total difference 16.50 milliseconds for 5,555,360 loops
The iteration variablity for Code 1 was (1.1172) milliseconds and Code 2 was (1.0372) milliseconds. The lower and the closer together there values are the more accurate the results are.
The first test, "rand()", was:
$key = rand(0, count($GLOBALS['array']) - 1); $GLOBALS['dummy'] = $GLOBALS['array'][$key];
The second test, "array_rand()", was:
$key = array_rand($GLOBALS['array'], 1); $GLOBALS['dummy'] = $GLOBALS['array'][$key];