C、python、php7 while速度比较_PHP_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > PHP > C、python、php7 while速度比较

C、python、php7 while速度比较

 2017/9/13 2:14:04  erntoo  程序员俱乐部  我要评论(0)
  • 摘要:先贴代码#include<stdio.h>voidmain(void){intcount=0,b;while(count<2+100000000){b=count;count++;}printf("Goodbye!");}故意多了个运算gcct.c-otcgcc-O2t.c-otc2#!/usr/bin/pythoncount=0while(count<100000000):b=countcount=count+1print"Goodbye!"#
  • 标签:PHP Python 速度

先贴代码

class="c" name="code">#include <stdio.h>
void main(void)
{
    int count=0,b;
    while(count < 2+100000000){
        b=count;
        count++;
    } 
    printf("Good bye!");
}

?故意多了个运算?

gcc? t.c -o tc

gcc -O2 t.c -o tc2

?

#!/usr/bin/python
count = 0
while (count < 100000000):
    b = count
    count = count + 1
print "Good bye!"

?

#!/usr/bin/php
<?php
$count=0;
while ($count < 100000000){
    $b=$count;
    $count++;
}
echo "Good bye!";

?

执行对比结果

[root@qxeden tmp]# time ./tc
Good bye!
real	0m0.376s
user	0m0.376s
sys	0m0.000s
[root@qxeden tmp]# time ./tc2
Good bye!
real	0m0.002s
user	0m0.000s
sys	0m0.002s
[root@qxeden tmp]# time ./t.py
Good bye!

real	0m23.721s
user	0m23.702s
sys	0m0.007s
[root@qxeden tmp]# time ./t.php
Good bye!
real	0m2.122s
user	0m2.111s
sys	0m0.010s

?

补充版本信息

[root@qxeden tmp]# gcc --version
gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-11)
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

[root@qxeden tmp]# php --version
PHP 7.1.9 (cli) (built: Aug 30 2017 20:06:08) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies
[root@qxeden tmp]# python --version
Python 2.7.5

?

?

?

?

上一篇: PHP 获取访客的信息 下一篇: 没有下一篇了!
发表评论
用户名: 匿名