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.

View test history (3) Run this test again Return to test menu

Result: Discarded

The test labeled "str_replace/strtolower" was the faster by 0.0794 seconds, (9.273% faster)

str_replace/strtolower 100%
str_ireplace 90.727%

The str_replace/strtolower test took 0.7772 seconds.
The str_ireplace test took 0.8567 seconds.

Nitty-Gritty

Each test case ran 20 random code order iterations consisting of 151,200 loops for a total of 3,024,000 runs.

  • Line execution difference (0.000026) milliseconds.
  • Avg difference (3.972) milliseconds per 151,200 loops.
  • Total difference 79.44 milliseconds for 3,024,000 loops

The iteration variablity for Code 1 was (7.4992) milliseconds and Code 2 was (6.7511) milliseconds. The lower and the closer together there values are the more accurate the results are.

Code

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 (7.2.25-1+ubuntu16.04.1+deb.sury.org+1)