Python speed vs csharp

Mike mike at nospam.com
Sat Aug 2 15:33:07 EDT 2003


On Wed, 30 Jul 2003 23:09:22 -0700, Mike wrote:

Wow. Thanks, everyone, for the suggestions. 

As noted in another reply, the full simulation calls the erfc function 150
milllion times, not 1.5 billion; the elapsed times are correct.

There doesn't appear to be any way to use previous results in the next
calculation. I'm calculating the output of a transmission line to a series
of input pulses. The input pulse sequence is not repetitive, so the output
doesn't asymptotically approach a final state.

I had tried the erfc function in the transcendental package (I can't
remember where I grabbed it from). I didn't try the scipy package, but
since I already had that installed, I should have tried that first.

Using psyco, the test case runs in 43 seconds. I was able to reduce that to
25 seconds using some of the improvements that Bengt Richter provided. I
was able to reduce the full simulation time down to 647 seconds; I'm sure
more improvements are possible, since I haven't implemented all of Bengt's
improvements. Part of the problem with the full simulation is that psyco
gobbles up all my available memory if I use psyco.full(), so I've been
experimenting with psyco.bind(). 647 seconds is my best result so far.

Psyco seems to do a good enough job of optimization that replacing lines
like 

   a1 = 0.254829542
   return ( (a1 + ...

with 

   return ( (0.254829542 + ...

don't result in any significant change in speed. In addition to the
math.exp call, the test case called the function like the full simulation
does, with a math.sqrt(c) in the call, which I replaced with sqrt =
math.sqrt, then replaced the x**2 with x*x. 

At first glance, I didn't think there was a way to "vectorize" the
simulation, but after looking at it a little more carefully, it's pretty
clear that there is. 

At this point, I'm within a factor of 2 of the c# results, and I'm pretty
much prepared to call that good enough to justify sticking with Python
instead of learning and converting to c#. 

Thanks again,

-- Mike --




More information about the Python-list mailing list