Real-world Python code 700 times slower than C

Chris Barker chrishbarker at attbi.com
Tue Jan 8 21:54:07 CET 2002


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.

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. Can anyone offer an explanation?

Note: this is important to me, as Python uses doubles for it's float, I
always use doubles with Numeric and C extensions, unless I'm concerned
about memory usage. Now I guess I have to take speed into account as
well.

-Chris


-- 
Christopher Barker,
Ph.D.                                                           
ChrisHBarker at attbi.net                ---           ---           ---
                                     ---@@       -----@@       -----@@
                                   ------@@@     ------@@@     ------@@@
Oil Spill Modeling                ------   @    ------   @   ------   @
Water Resources Engineering       -------      ---------     --------    
Coastal and Fluvial Hydrodynamics --------------------------------------
------------------------------------------------------------------------



More information about the Python-list mailing list