Test: array_diff vs. ==
Is using array_diff() better than an == check?
Run this test again Return to test menuResult: Discarded
The test labeled "array_diff()" was the faster by 0.0799 seconds, (6.867% faster)
The array_diff() test took 1.0836 seconds.
The == test took 1.1635 seconds.
Nitty-Gritty
Each test case ran 20 random code order iterations consisting of 290,263 loops for a total of 5,805,260 runs.
- Line execution difference (0.000014) milliseconds.
- Avg difference (3.995) milliseconds per 290,263 loops.
- Total difference 79.91 milliseconds for 5,805,260 loops
The iteration variablity for Code 1 was (3.4644) milliseconds and Code 2 was (6.1806) 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'];