Test: concat (string) vs. not
Is there any gain from casting to a string before concatenation?
View test history (1) Run this test again Return to test menuResult: Discarded
The test labeled "(string)" was the faster by 0.1844 seconds, (14.059% faster)
The (string) test took 1.127 seconds.
The no cast test took 1.3113 seconds.
Nitty-Gritty
Each test case ran 20 random code order iterations consisting of 288,913 loops for a total of 5,778,260 runs.
- Line execution difference (0.000032) milliseconds.
- Avg difference (9.218) milliseconds per 288,913 loops.
- Total difference 184.36 milliseconds for 5,778,260 loops
The iteration variablity for Code 1 was (6.4977) milliseconds and Code 2 was (13.4722) milliseconds. The lower and the closer together there values are the more accurate the results are.
Code
The first test, "(string)", was:
for ($j = 0; $j < 1000; $j++) $GLOBALS['dummy'] = 'good morning! ' . (string) $j . ' good night!';
The second test, "no cast", was:
for ($j = 0; $j < 1000; $j++) $GLOBALS['dummy'] = 'good morning! ' . $j . ' good night!';