python跟php计算性能差距到底有多大?
php版本7.1
<?php
$n=1;
$time=time();
while($n<100000000){
$n=$n+1;
}
echo time()-$time;
3秒
python版本3.7
8.27714991569519秒
python版本2.7
import time
n = 1
time_start = time.time()
while n < 100000000:
n = n+1
time_end = time.time()
print time_end - time_start
10.3120000362秒
斐波那契 php版本 7.1
<?php
/**
* Created by PhpStorm.
* User: dn
* Date: 2018/10/18
* Time: 17:17
*/
$startTime = time();
function f($a)
{
if ($a == 0 || $a == 1) {
return 1;
}
return f($a-1) + f($a-2);
}
for($i = 0; $i < 40; ++$i) {
echo f($i).' ';
}
$endTime = time();
echo $endTime-$startTime;
101秒
斐波那契 php版本 5.6
177秒
斐波那契 python2.7
182秒