Real-world Python code 700 times slower than C

Tim Hochberg tim.hochberg at ieee.org
Tue Jan 8 17:22:58 EST 2002


"Chris Barker" <chrishbarker at attbi.com>
 Tim Hochberg wrote:
> > By cheating a bit I came up with a version using Numeric that runs more
than
> > 50x faster than the original Python version. I didn't compare with the C
> > version directly, but this seems like it should put things back in the
> > 10-15x slower range. I'm cheating because I use an array of floats
instead
> > of doubles as the C code does
>
> When I first read this, I wondered why you bothered. With tests I have
> done in the past, I have found floats and doubles take about the same
> amount of time to compute stuff. Also, my understanding is that math
> co-processors (at least on Intel) use doubles internally anyway, so
> there is little to gain in speed by using floats.
>
> I tried re-writing your code with doubles, and it ended up more than
> four times slower, so now I know why you did it.

I think I was getting something like 10x slower! And like you I have no idea
why.

> Anyone know why this is? I can see that twice as much memory has to be
> allocated, de-allocated, and passed around, but that wouldn't account
> for a 4X slow down.

Particularly since (I think) I avoided any allocations and deallocations
except during the first time through.

>Can anyone offer an explanation?

Not I.

-tim






More information about the Python-list mailing list