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

Armin Rigo arigo at tunes.org
Tue Jun 10 13:06:27 CEST 2003


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.


A bientôt,

Armin.




More information about the Pyrex mailing list