It is well know that shifting bits to the left is faster than multiply because barrel shifters are implemented directly in the hardware. Therefore, this simple benchmark should be wrong:
$start = 1;
$timestart = microtime(1);
for ($i = 0; $i < 10000000; $i++) {
$result2 = $start << 2;
}
echo microtime(1) - $timestart;
$timestart = microtime(1);
for ($i = 0; $i < 10000000; $i++) {
$result1 = $start * 4;
}
echo microtime(1) - $timestart;
echo "\n";
Because I executed it multiple times and always multiplying was faster than shifting bits to the left. For example:
0.73733711242676
0.71091389656067
Therefore, or the benchmark is wrong or the PHP interpreter is doing something here. The test is executed by PHP 7.0.32 running in Ubuntu:
PHP 7.0.32-0ubuntu0.16.04.1 (cli) ( NTS )
CPU: Intel(R) Core(TM) i5-4460 CPU @ 3.20GHz
Edit:
Executing it in a Windows box, with almost the same CPU (Intel(R) Core(TM) i5-4460S CPU @2.90GHz) the results are like expected:
0.24960112571716
0.28080010414124
The PHP version for this case is different:
PHP 7.1.19 (cli) (built: Jun 20 2018 23:24:42) ( ZTS MSVC14 (Visual C++ 2015) x64 )