Result: Discarded
The test labeled "substr($var, -1)" was the faster by 0.007 seconds, (0.637% faster)
The substr($var, -1) test took 1.0958 seconds.
The strlen() test took 1.1028 seconds.
Nitty-Gritty
Each test case ran 20 random code order iterations consisting of 291,170 loops for a total of 5,823,400 runs.
- Line execution difference (0.000001) milliseconds.
- Avg difference (0.351) milliseconds per 291,170 loops.
- Total difference 7.02 milliseconds for 5,823,400 loops
The iteration variablity for Code 1 was (5.9522) milliseconds and Code 2 was (5.7403) milliseconds. The lower and the closer together there values are the more accurate the results are.
Code
The first test, "substr($var, -1)", was:
for ($j = 0; $j < 100; $j++) $GLOBALS['dummy2'] = substr($GLOBALS['dummy'], -1);
The second test, "strlen()", was:
for ($j = 0; $j < 100; $j++) $GLOBALS['dummy2'] = substr($GLOBALS['dummy'], strlen($GLOBALS['dummy']) - 1);