From: Tim H. <tim...@ie...> - 2003-06-10 14:58:40
|
Armin Rigo wrote: >Hello, > >On Mon, Jun 09, 2003 at 10:27:52PM +0000, sdfrost@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) : > > Oddly I don't see this speedup here: Windows XP using Psyco 1.0 on Python 2.2.2. The resulting code is easier to read but roughly the same speed or maybe just a tad slower. Have there been some speedups since 1.0 was put out? Perversely, where I do get a signifigant speed up is replacing "n % p1 == 0" with "(n // p1) * p1 == n". This speeds things up by almost 15%. I know that Python needs to jump through some hoops to make modulo work the Python way instead of the C way, and I assume that's what's slowing things down. If that really is the cause of the slowdown, would it be possible to recognize the "A % B == 0" case and use the raw C modulus there? I was going to try the latest version from CVS and see if it was faster and if there were any obvious bottlenecks involving modulus, but I can't get it to compile here. The compiler complains about not being able to find iencoding.h in vcompiler.h. Any hints for where I could find myself an iencoding.h file for cheap? -tim >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. > > >------------------------------------------------------- >This SF.net email is sponsored by: Etnus, makers of TotalView, The best >thread debugger on the planet. Designed with thread debugging features >you've never dreamed of, try TotalView 6 free at www.etnus.com. >_______________________________________________ >Psyco-devel mailing list >Psy...@li... >https://lists.sourceforge.net/lists/listinfo/psyco-devel > > > |