[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [pygame] Does anyone have a python implementation of A*?



Bob Ippolito <bob@threeoh.com>:
>
> I think the point of difference is that the for loops in list 
> comprehensions are more likely C for loops, like with the builtins (map, 
> reduce, zip, etc)

Maybe. I think I've heard otherwise, but I haven't checked the code,
so you may be right. Anyway, I tried the following simple test:

-------------------------------------
import time

SIZE = 1000000

t0 = time.time()
l = [0]*SIZE
for i in xrange(SIZE): l[i] = i
t1 = time.time()

print t1-t0

t0 = time.time()
l = [i for i in range(SIZE)]
t1 = time.time()

print t1-t0
-------------------------------------

The result was

3.18981695175
3.22544193268

The for loop is slightly faster than the list comprehension here. So,
I still strongly doubt that the use of list comprehensions itself can
have caused the 100x speedup. There are many other pitfalls that may
have caused a slowdown, of course... E.g. using

  lst = lst + [next_element]

(rather than using +=, append(), or extend())

would have to creat **lots** of lists... That in itself could easily
account for a slowdown of about 100. (Just try it -- the difference is
enormous.)

A peek at the original code could probably uncover any such blunders.

--
Magnus Lie Hetland                                  The Anygui Project
http://hetland.org                                  http://anygui.org
____________________________________
pygame mailing list
pygame-users@seul.org
http://pygame.seul.org