PHP Benchmarks

Performance comparison of PHP code alternatives.

Test: array_keys(array_flip) vs. array_unique

Do note that this test is only using integer values (which is common for this), long strings will take longer to hash as array keys.

Run this test again Return to test menu

Historical Results

Based on (16) saved test runs, The test labeled "array_keys(array_flip())" was (on average) the faster by 0.0057 seconds, (0.650% faster)

array_keys(array_flip()) 100%
array_unique() 99.35%

The array_keys(array_flip()) test took 0.8682 seconds.
The array_unique() test took 0.8739 seconds.


Each test case ran 20 random code order iterations consisting of 179,894 loops for a total of 3,597,870 runs.

  • Line execution difference (0.000002) milliseconds.
  • Avg difference (0.000) milliseconds per 179,894 loops.
  • Total difference 5.68 milliseconds for 3,597,870 loops

The iteration variablity for Code 1 was (0.0000) milliseconds and Code 2 was (0.0000) milliseconds. The lower and the closer together there values are the more accurate the results are.


The first test, "array_keys(array_flip())", was:

$array = array(1,2,3,4,5,6,7,8,9);
$a = 1;

if (in_array(1,$array) || $a)
	$b = true;

$array = array_keys(array_flip($array));

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

$array = array(1,2,3,4,5,6,7,8,9);
$a = 1;

if ($a || in_array(1,$array))
	$b = true;

Running: Linux (x86_64:1 GB) PHP (