C、python、php7 while速度比较

阅读更多

先贴代码

#include 
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
 
  

 

执行对比结果

[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


PHP5.6.31 补充
time ./t56.php 
Good bye!
real	0m7.599s
user	0m7.583s
sys	0m0.013s



 

补充版本信息

[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

 

 

 

 

你可能感兴趣的:(python,c,php,while,速度)