n-body problem at shootout.alioth.debian.org

Paddy paddy3118 at netscape.net
Sat Oct 7 01:49:31 EDT 2006


bearophileHUGS at lycos.com wrote:
> skip at pobox.com wrote:
> > Ah, wait a moment.  One more tweak.  Make the body class a psyco class.
> > That improves the runtime to 3.02s.  Diff appended.
>
> Nice. Maybe you can do the same trick with:
> from psyco.classes import __metaclass__
>
> If you want you can try that trick with this version of mine:
> http://shootout.alioth.debian.org/sandbox/benchmark.php?test=nbody&lang=psyco&id=3
>
> (I can't try it, precompiled Psyco doesn't exists yet for Py2.5). If
> it's faster, then I can upload some modified version...
>
> Bye,
> bearophile

You might also put the outer loop calling function advance so many
times, into the advance function:

==========
def advance(bodies, dt, n) :
    for i in xrange(n) :
        for i,b in enumerate(bodies) :

    ...

def main() :
    ...
    advance(bodies, 0.01, n)

==========

This I like. It points to areas of python where maybe we should be
adding to the standard library whilst also showing off the cream of the
non-standard libraries out their.

- Paddy.




More information about the Python-list mailing list