1. 程式人生 > >python比c,有多慢,小測試

python比c,有多慢,小測試

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