python跟php计算性能差距到底有多大?

php版本7.1
<?php


$n=1;
$time=time();
while($n<100000000){
   $n=$n+1;
}
echo time()-$time;
3秒

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秒

博客
请先登录后发表评论
  • 最新评论
  • 总共1条评论
白俊遥博客

ZZZ _JY:hello world

2018-10-22 18:27:39 回复

白俊遥博客
  • 白色彩虹 回复 ZZZ _JY:阿萨德环境安静啥都好说
  • 2018-10-22 18:29:39 回复