[Pyrex] Re: [Psyco-devel] Dynamic arrays, Pyrex and Psyco

Tim Hochberg tim.hochberg at ieee.org
Tue Jun 10 19:54:35 CEST 2003


Armin Rigo wrote:

>Hello,
>
>On Mon, Jun 09, 2003 at 10:27:52PM +0000, sdfrost at UCSD.EDU wrote:
>  
>
>>As I imagine that lots of people would like to use Pyrex and/or Psyco to 
>>reduce the overhead of Python loops, I'm attaching a modified primes example, 
>>in which the size of the array of results is determined at runtime, and 
>>compared the performance with standard Python code and Psyco-accelererated 
>>code.
>>    
>>
>
>Note that Psyco performs better if you write the loops in a more Pythonic 
>style (which is an example of what I like to emphasis: given good tools it is 
>in the *interest* of performance to write higher-level code) :
>
>def primes(kmax):
>  p = []
>  n = 2
>  while len(p) < kmax:
>    for p1 in p:
>      if n % p1 == 0:
>        break
>    else:
>      p.append(n)
>    n = n + 1  
>  return p
>
>With Psyco, this only needs 80% of the time needed by your original example.  
>Surely enough Pyrex is still faster.
>  
>

I looked into this a little and it turns out that Psyco currently does 
not psycoize integer modulo or division. I went ahead and added the code 
to do this(*) and immediately Armin's code above ran 22 times faster 
than the unpsycoized code. I don't have Pyrex handy, but based on the 
earler description, with this change they end up being about the same speed.

-tim

(*) The change is a little half baked -- it's implemented the same way 
the floating point operations are and as a result is probably not as 
fast as the other integer operations. This is because trying to mess 
with the stuff in the i386 folder makes my brain melt, so I just stuck 
with playing with pintobject.






More information about the Pyrex mailing list