Monday, 14 January 2008

Evaluate Python speed (datetime->timedelta)

We can evaluate the following script with python and jython to work out which is faster.

import datetime

t1= datetime.datetime.now()

j=0
k=100000
for i in range(1,k):
j=j+i

print # to print a new line

t2= datetime.datetime.now()

tstr=[(t2-t1).seconds,(t2-t1).microseconds] # the attributes of timedelta class: senconds and microseconds, from http://docs.python.org/lib/datetime-timedelta.html#l2h-602
print 'Accumulated from 1-',k,': ',j
print tstr

No comments:

My photo
London, United Kingdom
twitter.com/zhengxin

Facebook & Twitter