wilk@blakie:/tmp$ python2.2 test.py
(54.152738928794861, 4.291534423828125e-05, 54.152696013450623, 'k=26991000000')
wilk@blakie:/tmp$ python2.3 test.py
(26.460186958312988, 4.291534423828125e-05, 26.46014404296875, 'k=26991000000')
Pour ce genre de chose psyco (http://psyco.sf.net(...)) est ton ami
wilk@blakie:/tmp$ python2.3 test.py
(10.823675036430359, 0.0006160736083984375, 10.82305896282196, 'k=26991000000')
Et si on veut se donner un peu plus de peine, pyrex est ton meilleur ami ;-)
wilk@blakie:/tmp$ python2.2 runc.py
(0.32985889911651611, 0.0, 0.32985889911651611, 'k=26991000000')
Pour ceux qui auraient peur de faire un module C pour python, voilà le code pour pyrex (http://www.cosc.canterbury.ac.nz/~greg/python/Pyrex(...)), cherchez les 7 différences avec la version python ;-) :
fichier c.pyx :
import time
def speedC(N):
cdef double k
cdef int i
cdef int j
t1 = t1b = time.time()
k = 0
for i from 0<= i <N:
for j from 0<= j <N:
k = k + (i + j)
t2 = time.time()
return ( t2-t1, t1b - t1, t2 - t1b , "k=%.f"%k)
et runc.py :
import c
print c.speedC(3000)
[^] # Re: Deux mesures suffisent
Posté par wilk . En réponse à la dépêche Python 2.3 est sorti. Évalué à 1.