python,java,c,c++ 效率比较

$ cat test.py
sum=0
for i in range(100000*10000):
    sum += i
print sum    
[]$ time python test.py
499999999500000000


real    3m37.687s
user    3m22.448s
sys     0m15.127s
[]$ time pypy test.py
499999999500000000


real    0m10.573s
user    0m10.540s
sys     0m0.021s


[]$ cat test.java


public class test{
    public static void main(String[] args)
    {
        long i=0,sum=0;
        for(;i<100000*10000;i++)
            sum += i;
        System.out.printf("%d\n",sum);         
    }

[]$ java test
499999999500000000
[]$ time java test
499999999500000000


real    0m0.862s
user    0m0.854s
sys     0m0.013s


[]$ cat test.cpp
#include <stdio.h>


int main(int argc,char * args[])
{
    long sum = 0;
    long i = 0;
    for ( ;i< 100000*10000;i++)
        sum += i;
    printf("%ld\n",sum);    
}


[]$ time ./testcpp 
499999999500000000


real    0m3.467s
user    0m3.465s
sys     0m0.000s


[]$ g++ -O test.cpp -o testcpp
[]$ time ./testcpp 
499999999500000000


real    0m0.002s
user    0m0.001s
sys     0m0.000s


[]$ cat test.c
#include <stdio.h>


int main(int argc,char * args[])
{
    long sum = 0;
    long i = 0;
    for ( ;i< 100000*10000;i++)
        sum += i;
    printf("%ld\n",sum);    
}
[]$ gcc test.c -O testc
gcc: testc: No such file or directory
[]$ gcc test.c -o testc
[]$ time ./testc
499999999500000000


real    0m3.500s
user    0m3.495s
sys     0m0.004s
[]$ gcc -O test.c -o testc
[]$ time ./testc
499999999500000000


real    0m0.001s
user    0m0.000s
sys     0m0.000s
[]$ gcc -O2 test.c -o testc
[]$ time ./testc
499999999500000000


real    0m0.001s
user    0m0.001s
sys     0m0.000s


>>> (100000*10000)/(3*60+37.687)
4593751.5791021055
>>> 
>>> (3*60+37.687)/(100000*10000)
2.1768700000000001e-07


>>> (100000*10000)/(10.54)
94876660.341555983


>>> (100000*10000)/(0.850)
1176470588.2352941
>>> 0.850/(100000*10000)
8.4999999999999996e-10


>>> (100000*10000)/(3.495)
286123032.90414876
>>> 3.495/(100000*10000)
3.495e-09


>>> (100000*10000)/(0.001)
1000000000000.0
>>> 0.001/(100000*10000)
9.9999999999999998e-13


python  202.448s   202448  4593751 4.59*10(6)   20 
pypy    10.540s   10540   94876660 9.48*10(7)  3 
cpp     3.465s   3465     286123032 2.86*10(8)   4
java    0.850s   854     1176470588 1.176*10(9) 1
cpp-O   0m0.001s    1
c       3.495s  3495
c-O     0.000s  1
c-O2    0m0.001s 1







  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值