I'm attaching the modified benchmarking script.
[...]
def ScreenTranslationTestVec2d(loop_count):
for i in xrange(loop_count):
final_pos = (TestData.object_position_tuple - TestData.screen_offset_tuple)*TestData.screen_scale
def ScreenTranslationTestVec2dTuple(loop_count):
for i in xrange(loop_count):
final_pos = (TestData.object_position_tuple - TestData.screen_offset_tuple)*TestData.screen_scale
Shouldn't the first function use the variables without the "_tuple" suffix?
<function ScreenTranslationTestVec2d at 0x009E3630> runs at 40641.4 loops/s that's 677.36 loops to fill 60 fps or 33.87 at a 5.0% budget at 60 fps
<function ScreenTranslationTestVec3 at 0x009E3230> runs at 171071.2 loops/s that's 2851.19 loops to fill 60 fps or 142.56 at a 5.0% budget at 60 fps
Doing vector operations one at a time in Python is always going to be either slow or very slow, no matter how you go about it.
IMO, the best way to make this sort of thing fast is to arrange things so that you can use Numeric to operate on multiple vectors at once. For instance, store all your object positions in one array and all the velocities in another, and then just add the two arrays together.
I used something like this very effectively in a
recent project where I wanted to find the intersection
of a ray with a terrain mesh.
- Matthias -