[Python-Dev] Numerical robustness, IEEE etc.
Paul Moore
p.f.moore at gmail.com
Wed Jun 21 17:11:17 CEST 2006
On 6/21/06, Fredrik Lundh <fredrik at pythonware.com> wrote:
> Nick Coghlan wrote:
>
> >> 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.
>
> how fast does the corresponding C program run ?
A horribly crude test using Regina Rexx (which implements the Decimal
standard in C, but I know nothing else about how):
x = 1.0
do 10000000
y = x + x
end
This takes about 5 sec on my PC, which (if I've calculated correctly)
comes out at 0.5 usec per loop.
I suppose it gives a ballpark figure for the sorts of speeds we can
expect from a C implementation.
Paul.
More information about the Python-Dev
mailing list