Wednesday, May 6, 2009

Python Decimals are really slow

10.4. decimal — Decimal fixed point and floating point arithmetic — Python v2.6.2 documentation

In [182]: rparts = lambda d: map(int, (floor(d), round(100*(d%1),0)))

In [183]: rparts(dyyyymm)
Out[183]: [2009, 5]

In [184]: rparts(fyyyymm)
Out[184]: [2009, 5]

In [185]: timing(rparts,10000,dyyyymm)
<lambda> 9.03

In [186]: timing(rparts,10000,fyyyymm)
<lambda> 0.28


Note:  the timing function I'm using here is the same one referred to in an earlier post "Timing is everything". 


No comments:

Post a Comment