Test: preg_replace vs. str_replace
No Description
View test history (2) Run this test again Return to test menuResult: Discarded
The test labeled "preg_replace()" was the faster by 0.0262 seconds, (4.957% faster)
The preg_replace() test took 0.5023 seconds.
The str_replace() test took 0.5285 seconds.
Nitty-Gritty
Each test case ran 20 random code order iterations consisting of 113,092 loops for a total of 2,261,840 runs.
- Line execution difference (0.000012) milliseconds.
- Avg difference (1.310) milliseconds per 113,092 loops.
- Total difference 26.20 milliseconds for 2,261,840 loops
The iteration variablity for Code 1 was (5.7421) milliseconds and Code 2 was (6.9557) milliseconds. The lower and the closer together there values are the more accurate the results are.
Code
The first test, "preg_replace()", was:
$GLOBALS['dummy2'] = preg_replace('~([Ww]heat|[Tt]hins)~', 'Nilla', $GLOBALS['dummy']);
The second test, "str_replace()", was:
$GLOBALS['dummy2'] = str_replace(array('Wheat', 'Thins', 'wheat', 'thins'), 'Nilla', $GLOBALS['dummy']);