[Python-Dev] Numerical robustness, IEEE etc.

Nick Coghlan ncoghlan at gmail.com
Wed Jun 21 13:22:14 CEST 2006


Facundo Batista wrote:
> 2006/6/20, Nick Coghlan <ncoghlan at gmail.com>:
>> The intent was always to replace the internal use of tuples and longs 
>> with a
>> more efficient C implementation - that particular step simply wasn't 
>> needed
>> for the original use case that lead Facundo to write and implement PEP 
>> 327.
> 
> Right. We never addressed speed. I mean, we made Decimal as fast as we
> could in the limited time we had (Raymond H. helped a lot also here),
> but it was NOT designed for speed.

As I recall, the design flow was pretty much 'make it work to spec' then 'make 
it run the telco benchmark and the tests faster while still keeping the 
implementation reasonably simple'. Helping Raymond with that tuning process 
was actually my first real contribution to CPython, so I got a lot of reading 
done while waiting for the benchmark and the decimal arithmetic tests to run 
with the Python profiler enabled ;)

Even then, I believe only two particularly significant changes were made to 
the implementation - adding the boolean flag so special values could be 
detected easily, and copping the conversion costs to & from longs for 
coefficient arithmetic, because we made the time back in the long run by 
getting to use the C-coded long arithmetic operations.

> BTW, prove me Decimal is not fast enough, ;)

C:\Python24>python -m timeit -s "x = 1.0" "x+x"
10000000 loops, best of 3: 0.137 usec per loop

C:\Python24>python -m timeit -s "from decimal import Decimal as d; x = d(1)" "x+x"
10000 loops, best of 3: 48.3 usec per loop

I don't really know my definition of 'fast enough to be the basic floating 
point type', but I'm pretty sure that a couple of orders of magnitude slower 
isn't it. I guess I'll find out what my definition is if the C implementation 
manages to get there ;)

(Hmm - a couple of spot checks makes it look like the decimal module's slowed 
down by a few percent in Python 2.5. It's probably worth trying out the new 
profiler on the module to see if there are any simple fixes to be made before 
beta 2. . .)

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia
---------------------------------------------------------------
             http://www.boredomandlaziness.org


More information about the Python-Dev mailing list