Test: str_ireplace vs. strtolower + str_replace
Replace a string, regardless of its case, with an uppercase variant. 10 replacements in a 750 character line. str_replace/strtolower does not preserve existing case of the rest of the string.View test history (5) Run this test again Return to test menu
Result: DiscardedThe test labeled "str_replace/strtolower" was the faster by 0.027 seconds, (3.652% faster)
The str_replace/strtolower test took 0.7116 seconds.
The str_ireplace test took 0.7386 seconds.
Each test case ran 20 random code order iterations consisting of 163,728 loops for a total of 3,274,560 runs.
- Line execution difference (0.000008) milliseconds.
- Avg difference (1.349) milliseconds per 163,728 loops.
- Total difference 26.97 milliseconds for 3,274,560 loops
The iteration variablity for Code 1 was (10.5814) milliseconds and Code 2 was (7.0541) milliseconds. The lower and the closer together there values are the more accurate the results are.
The first test, "str_ireplace", was:
str_ireplace('sTrIng', 'STRING!', $GLOBALS['dummy']);
The second test, "str_replace/strtolower", was:
str_replace('string', 'STRING!', strtolower($GLOBALS['dummy']));