[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Python and Speed



Ian Mallett wrote:
What is the difference between a tree and a cell?  Cells
are regular?

Yes. The term "tree" implies a recursive data structure --
in this case, that the "cells" can be further divided
into subcells, and those into subsubcells, etc., to
arbitrary depth.

If the division only goes one level deep, it's not
a "tree" in computer science terms, it's just an array.

By "can't be that hard", I mean that if C++ can do it, Python should be able to too.

Several people have pointed out the reasons why that line
of thinking is seriously flawed.

if I can make optimizations in my code, they should be able
> to make modifications in Python.

Making manual optimisations to particular aspects of a
particular game program is one thing. Doing the same
thing automatically, in general, for any Python program
is something quite different.

> If I had decided to spend the time to code something with all
of the optimizations, it would take longer.

If the more-efficient algorithm is substantially harder
to code, or results in obscure code that is harder to
maintain, then yes, you should try a simpler approach
first.

But sometimes there is a better approach that isn't
much more difficult to do up front, such as using
a quicksort or mergesort rather than a bubble sort.
The code isn't much bigger, and it's guaranteed to
perform reasonably well however big the data gets,
so it would be silly not to use it in the first place.

That probably doesn't apply in this case -- the test-
everything-against-everything approach is very easy
to try out compared to the alternatives, and it might
be fast enough.

But even if it's fast enough for the cases you test it
on, it might not be fast enough for all the cases
encountered when you put it into production. Maybe it's
okay for the 100 sprites in the level you release with
the game, but if the game has a level editor, and someone
tries to use 1000 sprites, they could be disappointed.

Whereas if you put in a bit more effort and use a considerably
better algorithm, they could use 10,000 sprites and conclude
that your game is totally awesome!

--
Greg