PHP Benchmarks

Performance comparison of PHP code alternatives.

Test: array_unique vs. !isset (integers)

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

Result: Discarded

The test labeled "!isset()" was the faster by 0.0897 seconds, (6.504% faster)

!isset() 100%
array_unique() 93.496%

The !isset() test took 1.2888 seconds.
The array_unique() test took 1.3785 seconds.

Nitty-Gritty

Each test case ran 20 random code order iterations consisting of 275,126 loops for a total of 5,502,520 runs.

  • Line execution difference (0.000016) milliseconds.
  • Avg difference (4.483) milliseconds per 275,126 loops.
  • Total difference 89.66 milliseconds for 5,502,520 loops

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

Code

The first test, "!isset()", was:

$array = array();
for ($n = 0; $n < 8; $n++)
	for ($i = 0; $i < 50; $i++)
	{
		if (!isset($array[$i]))
			$array[$i] = $i;
	}

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

$array = array();
for ($n = 0; $n < 8; $n++)
{
	for ($i = 0; $i < 50; $i++)
		$array[] = $i;
}

$array = array_unique($array);

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