Test: stripos vs. strtolower(substr)
Case insensitive search a string for a set of characters.
Run this test again Return to test menuResult: Discarded
The test labeled "strtolower(substr())" was the faster by 0.0483 seconds, (9.032% faster)
The strtolower(substr()) test took 0.4863 seconds.
The stripos() test took 0.5346 seconds.
Nitty-Gritty
Each test case ran 20 random code order iterations consisting of 133,853 loops for a total of 2,677,060 runs.
- Line execution difference (0.000018) milliseconds.
- Avg difference (2.414) milliseconds per 133,853 loops.
- Total difference 48.28 milliseconds for 2,677,060 loops
The iteration variablity for Code 1 was (4.8421) milliseconds and Code 2 was (1.3071) milliseconds. The lower and the closer together there values are the more accurate the results are.
Code
The first test, "stripos()", was:
for ($j = 0; $j < 100; $j++) $GLOBALS['dummy2'] = stripos($GLOBALS['dummy'], 'xyz') != '';
The second test, "strtolower(substr())", was:
for ($j = 0; $j < 100; $j++) $GLOBALS['dummy2'] = strtolower(substr($GLOBALS['dummy'], 24, 4) == 'xyz');