<p>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?</p>
<div class="gmail_quote">Den 14 aug 2011 18.58 skrev "Timo Paulssen" <<a href="mailto:timonator@perpetuum-immobile.de">timonator@perpetuum-immobile.de</a>>:<br type="attribution">> Hello List,<br>> <br>
> I'm currently experimenting with a piece of software I've recently started<br>> maintaining, which is a cellular automaton simulation software. It's supposed to<br>> make experimenting easy, but still be fast at simulating. As you might know, all<br>
> cellular automatons operate in steps, where usually the whole "configuration<br>> space" is iterated over and all fields are updated depending on their<br>> neighbourhood and the "local transition function". Currently, the step functions<br>
> are implemented in C and inlined with weave.inline.<br>> <br>> The experiment I just tried out was generating step functions by piecing<br>> together strings of C code. It was quite successful, but I would like to take<br>
> that one step further and use python code instead of having the user write C<br>> code that has to be written with weave in mind.<br>> <br>> The first attempt at making it work with python code was to put python callables<br>
> into lists and running them somewhat like this:<br>> <br>> def step_pure_py(self):<br>> runhooks("init")<br>> loop_iter = self.loop.get_iter()<br>> for pos in loop_iter:<br>> runhooks("pre_compute")<br>
> runhooks("compute")<br>> runhooks("post_compute")<br>> runhooks("after_step")<br>> <br>> This is utterly slow, because - even though i turned the lists that contain the<br>
> hooks into tuples - i have no way to tell pypy, that the lists are not going to<br>> be changed and all loops that handle them can safely be unrolled.<br>> <br>> Unrolling the lists by hand gives me insane speedups. These are timings for<br>
> 10.000 steps on a 1000 field array - that is calling step_pure_py 1000 times and<br>> having the loop_iter iterate over 1000 fields each time.<br>> <br>> hand-unrolled python code:<br>> 2.15user 0.01system 0:02.18elapsed 99%CPU (0avgtext+0avgdata 103024maxresident)k<br>
> <br>> hook based solution like above:<br>> 62.57user 0.05system 1:02.79elapsed 99%CPU (0avgtext+0avgdata 184576maxresident)k<br>> <br>> So what would you suggest for making this much faster? I read on the IRC, that<br>
> in pypy itself, string concatenation is actually used to create python<br>> functions, so maybe that would be way to go in this case? Or could pypy offer<br>> decorators or other hints to cause pypy to unroll and constant-fold different<br>
> things for me?<br>> <br>> Thank you<br>> - Timo Paulssen<br>> _______________________________________________<br>> pypy-dev mailing list<br>> <a href="mailto:pypy-dev@python.org">pypy-dev@python.org</a><br>
> <a href="http://mail.python.org/mailman/listinfo/pypy-dev">http://mail.python.org/mailman/listinfo/pypy-dev</a><br></div>