The bash terminal used was installed using this tutorial. I don't think using a different cli matters for the execution time of php (as there was no difference between git bash and windows cmd) but for the purpose of making a clear distinction, I refer to it as "executed from bash" (refering to Ubuntu bash terminal), or "executed from git bash" (refering to the git bash terminal for Windows 10).
I have executed the script below a bunch of ways:
1: two seperate windows computers with a MAMP (Pro) and XAMPP stack, which had similar outcomes averaging at about 5.9 seconds.
2: Executed it with php for windows 10 without a LAMP or XAMPP stack, averaging at about 5.1 seconds.
3: However, when I execute this code via a Bash terminal (PHP 7.1.26-1+ubuntu18.04.1+deb.sury.org+1 (cli)) the avg execution time is around 2.9 seconds.
<?php
$j=0;
$startTime = microtime(1);
for($i = 0; $i < 199999999; $i++ ){
$j+=4;
}
$time = microtime(1) - $startTime;
exit(var_dump($time));
What I have done so far
Tried running it with -n parameter (which disables the php.ini) from cli so any extensions that could be slowing the proces down would be disabled, but this made no difference:
php test.php -n
Tried running it as webserver to see if it would make a difference, and this caused the server started from BASH terminal to be 300ms faster than executed in cli, so 2.6 seconds. However, it did not matter for the command executed from git bash:
php -S localhost:8080 -n
Measured differences between real, user and system time, which has quite a big difference in outcome, averaged 10 times on git bash and bash:
Bash
real: 0m2.993s
user: 0m2.938s
sys: 0m0.063s
Git bash
real: 0m5.923s
user: 0m0.015s
sys: 0m0.030s
time php test.php -n
I have no clue where to look further, as it's just the php execution time i am concerned about, for now. Hope someone can help :).