[pypy-dev] Efficiently piecing together callables with hooks?
neppord at gmail.com
Mon Aug 15 10:18:26 CEST 2011
Hi, i only have some questions about your example code. How does the
runhooks function work? And what are you using the pos loop variable for?
Den 14 aug 2011 18.58 skrev "Timo Paulssen" <timonator at perpetuum-immobile.de
> Hello List,
> I'm currently experimenting with a piece of software I've recently started
> maintaining, which is a cellular automaton simulation software. It's
> make experimenting easy, but still be fast at simulating. As you might
> cellular automatons operate in steps, where usually the whole
> space" is iterated over and all fields are updated depending on their
> neighbourhood and the "local transition function". Currently, the step
> are implemented in C and inlined with weave.inline.
> The experiment I just tried out was generating step functions by piecing
> together strings of C code. It was quite successful, but I would like to
> that one step further and use python code instead of having the user write
> code that has to be written with weave in mind.
> The first attempt at making it work with python code was to put python
> into lists and running them somewhat like this:
> def step_pure_py(self):
> loop_iter = self.loop.get_iter()
> for pos in loop_iter:
> This is utterly slow, because - even though i turned the lists that
> hooks into tuples - i have no way to tell pypy, that the lists are not
> be changed and all loops that handle them can safely be unrolled.
> Unrolling the lists by hand gives me insane speedups. These are timings
> 10.000 steps on a 1000 field array - that is calling step_pure_py 1000
> having the loop_iter iterate over 1000 fields each time.
> hand-unrolled python code:
> 2.15user 0.01system 0:02.18elapsed 99%CPU (0avgtext+0avgdata
> hook based solution like above:
> 62.57user 0.05system 1:02.79elapsed 99%CPU (0avgtext+0avgdata
> So what would you suggest for making this much faster? I read on the IRC,
> in pypy itself, string concatenation is actually used to create python
> functions, so maybe that would be way to go in this case? Or could pypy
> decorators or other hints to cause pypy to unroll and constant-fold
> things for me?
> Thank you
> - Timo Paulssen
> pypy-dev mailing list
> pypy-dev at python.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the pypy-dev