This is not an issue, but I decided that it might be interesting.
I have just discovered that code written in Python+Psyco can be faster then Panda’s own built-in functions. You can try it yourself (of course, requires Psyco to be installed with Panda’s Python).
import psyco psyco.profile() def dot_vectors(U, V): '''Returns dot product of two 2D vectors. Requires vectors U and V given as two (x,y) tuples.''' Ux, Uy, Vx, Vy = U+V return Ux*Vx + Uy*Vy
from pandac.PandaModules import Vec2 from test_module import dot_vectors import timeit # Best result: 0.368945773834 seconds U = Vec2(1, 2) setup = "from __main__ import U" t = timeit.Timer("U.dot(U)", setup = setup) print min(t.repeat(10)) # Best result: 0.131737692919 seconds U = (1, 2) setup = "from __main__ import U, dot_vectors" t = timeit.Timer("dot_vectors(U, U)", setup = setup) print min(t.repeat(10))
I am writing complicated code for goal-oriented planner, pathfinding and steering behaviors for game with dozens of units on screen, and this discovery became very important. The performance is much better now.
Just wanted to share these thoughts with fellow community…