现在的位置: 首页 > 综合 > 正文

python比c,有多慢,小测试

2017年08月26日 ⁄ 综合 ⁄ 共 393字 ⁄ 字号 评论关闭

gcc version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5)

Python 2.7.3

 

 

#include <stdlib.h>
#include <time.h>

int main ()
{
    int st = time(NULL);
    long a = 100.33;
    long b = 23.33;
    long c;
    int ct = 1000000000;
    for (; ct > 0; ct --)
        c = a/++b;

    printf("\n total time: %d\n", time(NULL)-st);
}

 

total time:  5s

import time

st = time.time()
a = 100.33
b = 23.33
ct = 100000
dt = 10000

for v in range(ct) :
    for j in range(dt) :
        c = a/++b

print "total time:", time.time()-st

total time:   242 s

 

 

抱歉!评论已关闭.