[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [pygame] Does anyone have a python implementation of A*?
John Eikenberry <jae@zhar.net>:
>
> Hmm... I didn't make many other changes besides what was needed to
> change to comprehensions. I'll mess around more to test what is actually
> responsible.
How did you build the list before changing to list comprehensions? In
my example I preallocated a list of the correct length, which will
give you roughly the same performance as a list comprehension. (The
plain for loop seems a tad faster -- I'm not sure exactly why.) Using
append() or += will give you slightly lower performance (with += being
slower than append) but nothing drastic. About a factor 2 for +=. If,
however, you do something that creates a lot of lists, such as
thelist = thelist + [newitem]
then things will start going really wrong. My tests indicate an
slowdown factor of about 100, as you reported in your program.
> Just to be sure we're all on the same page, I'm using python 2.1.2.
2.2 here.
--
Magnus Lie Hetland The Anygui Project
http://hetland.org http://anygui.org
____________________________________
pygame mailing list
pygame-users@seul.org
http://pygame.seul.org