Test: strstr vs. strpos
10 character string, check if a substring exists in a defined location.
Run this test again Return to test menuResult: Discarded
The test labeled "strpos()" was the faster by 0.062 seconds, (5.151% faster)
The strpos() test took 1.1422 seconds.
The strstr() test took 1.2042 seconds.
Nitty-Gritty
Each test case ran 20 random code order iterations consisting of 293,000 loops for a total of 5,860,000 runs.
- Line execution difference (0.000011) milliseconds.
- Avg difference (3.101) milliseconds per 293,000 loops.
- Total difference 62.03 milliseconds for 5,860,000 loops
The iteration variablity for Code 1 was (10.6596) milliseconds and Code 2 was (4.6378) milliseconds. The lower and the closer together there values are the more accurate the results are.
Code
The first test, "strstr()", was:
for ($j = 0; $j < 100; $j++) $GLOBALS['dummy2'] = strstr($GLOBALS['dummy'], '3456') != '';
The second test, "strpos()", was:
for ($j = 0; $j < 100; $j++) $GLOBALS['dummy2'] = strpos($GLOBALS['dummy'], '3456') !== false;