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 (4) Run this test again Return to test menu
Result: DiscardedThe test labeled "str_ireplace" was the faster by 0.0763 seconds, (5.732% faster)
The str_ireplace test took 1.2551 seconds.
The str_replace/strtolower test took 1.3314 seconds.
Each test case ran 20 random code order iterations consisting of 263,834 loops for a total of 5,276,680 runs.
- Line execution difference (0.000014) milliseconds.
- Avg difference (3.816) milliseconds per 263,834 loops.
- Total difference 76.31 milliseconds for 5,276,680 loops
The iteration variablity for Code 1 was (4.7694) milliseconds and Code 2 was (6.2239) 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']));