PHP Benchmarks

Performance comparison of PHP code alternatives.

Test: array_diff vs. ==

Is using array_diff() better than an == check?

Run this test again Return to test menu

Historical Results

Based on (14) saved test runs, The test labeled "array_diff()" was (on average) the faster by 0.0021 seconds, (0.242% faster)

array_diff() 100%
== 99.758%

The array_diff() test took 0.8723 seconds.
The == test took 0.8744 seconds.

Nitty-Gritty

Each test case ran 20 random code order iterations consisting of 217,625 loops for a total of 4,352,491 runs.

  • Line execution difference (0.000000) milliseconds.
  • Avg difference (0.000) milliseconds per 217,625 loops.
  • Total difference 2.12 milliseconds for 4,352,491 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.

Code

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

for ($n = 0; $n < 20; $n++)
	$GLOBALS['dummy2'] = count(array_diff($GLOBALS['dummy'], $GLOBALS['dummy_pass'], $GLOBALS['dummy_pass2'])) === 0;
for ($n = 0; $n < 20; $n++)
	$GLOBALS['dummy2'] = count(array_diff($GLOBALS['dummy'], $GLOBALS['dummy_fail'], $GLOBALS['dummy_fail2'])) === 0;

The second test, "==", was:

for ($n = 0; $n < 20; $n++)
	$GLOBALS['dummy2'] = $GLOBALS['dummy'] == $GLOBALS['dummy_pass'] && $GLOBALS['dummy'] == $GLOBALS['dummy_pass2'];
for ($n = 0; $n < 20; $n++)
	$GLOBALS['dummy2'] = $GLOBALS['dummy'] == $GLOBALS['dummy_fail'] && $GLOBALS['dummy'] == $GLOBALS['dummy_fail2'];

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