PHP Benchmarks

Performance comparison of PHP code alternatives.

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.

Run this test again Return to test menu

Historical Results

Based on (3) saved test runs, The test labeled "str_ireplace" was (on average) the faster by 0.0057 seconds, (0.913% faster)

str_ireplace 100%
str_replace/strtolower 99.087%

The str_ireplace test took 0.6176 seconds.
The str_replace/strtolower test took 0.6233 seconds.


Each test case ran 20 random code order iterations consisting of 167,614 loops for a total of 3,352,287 runs.

  • Line execution difference (0.000002) milliseconds.
  • Avg difference (0.000) milliseconds per 167,614 loops.
  • Total difference 5.69 milliseconds for 3,352,287 loops

The iteration variablity for Code 1 was (0.0000) milliseconds and Code 2 was (0.0000) 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']));

Running: Linux (x86_64:1 GB) PHP (