Test: substr_compare vs strpos
4800 character string, check if a substring exists in a defined location.
View test history (2) Run this test again Return to test menuResult: Discarded
The test labeled "substr_compare" was the faster by 0.0127 seconds, (2.448% faster)
The substr_compare test took 0.5065 seconds.
The strpos test took 0.5192 seconds.
Nitty-Gritty
Each test case ran 20 random code order iterations consisting of 142,955 loops for a total of 2,859,100 runs.
- Line execution difference (0.000004) milliseconds.
- Avg difference (0.636) milliseconds per 142,955 loops.
- Total difference 12.71 milliseconds for 2,859,100 loops
The iteration variablity for Code 1 was (0.6617) milliseconds and Code 2 was (1.1745) milliseconds. The lower and the closer together there values are the more accurate the results are.
Code
The first test, "substr_compare", was:
$test = substr_compare($GLOBALS['dummy'], 'ghi', 6, 3) === 0;
The second test, "strpos", was:
$test = strpos($GLOBALS['dummy'], 'ghi', 6) === 6;