Real-world Python code 700 times slower than C

Cliff Wells logiplexsoftware at earthlink.net
Tue Jan 8 18:12:09 EST 2002


On Tue, 08 Jan 2002 12:54:07 -0800
Chris Barker <chrishbarker at attbi.com> wrote:

> 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.


"Of course, the x86 architecture doesnt really care about data alignment 
or does it? In fact, while the x86 wont kill your program for misaligned
data, accessing that data will slow your program down. For example, on my
133Mhz Pentium, accessing a properly aligned array of doubles (aligned on
an eight-byte boundary) was about twice as fast as accessing an improperly
aligned array of doubles (aligned on a four-byte boundary). The case of
arrays of doubles is worth considering. A lot of scientific and engineering
applications operate on large matrices that are essentially arrays of type
double. If you allocate those matrices with a version of malloc() that does
not guarantee eight-byte alignment, youre needlessly incurring a heavy
penalty in processing time."

This quote is from:

http://www.wd-mag.com/articles/1999/9904/9904a/9904a.htm?topic=articles

-- 
Cliff Wells
Software Engineer
Logiplex Corporation (www.logiplex.net)
(503) 978-6726 x308
(800) 735-0555 x308




More information about the Python-list mailing list