Result: DiscardedThe test labeled "preg_replace()" was the faster by 0.0878 seconds, (6.468% faster)
The preg_replace() test took 1.27 seconds.
The str_replace() test took 1.3578 seconds.
Each test case ran 20 random code order iterations consisting of 284,649 loops for a total of 5,692,980 runs.
- Line execution difference (0.000015) milliseconds.
- Avg difference (4.391) milliseconds per 284,649 loops.
- Total difference 87.82 milliseconds for 5,692,980 loops
The iteration variablity for Code 1 was (7.7237) milliseconds and Code 2 was (10.8115) milliseconds. The lower and the closer together there values are the more accurate the results are.
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']);